Author SHA1 Message Date
spark 0998a016fa ci(runtime): add PHP 8.5 and Node 24.22.1 CI workflow (BIT-31720)
ci / verify (pull_request) Successful in 41s
Paperclip-Issue: BIT-31720
2026-10-23 18:36:29 +01:00
spark e160520655 chore(runtime): pin .nvmrc to 24.22.1 (BIT-31720)
Paperclip-Issue: BIT-31720
2026-10-23 18:36:27 +01:00
spark 4998a0f009 chore(runtime): set engines.node >=24.22.1 in admin-ui (BIT-31720)
Paperclip-Issue: BIT-31720
2026-10-23 18:36:26 +01:00
spark a782a97a1d chore(runtime): update admin-ui/Dockerfile to latest PHP/Node baseline (BIT-31720)
Paperclip-Issue: BIT-31720
2026-10-23 18:36:23 +01:00
spark c0c3109174 chore(runtime): update web/Dockerfile to latest PHP/Node baseline (BIT-31720)
Paperclip-Issue: BIT-31720
2026-10-23 18:36:20 +01:00
spark 4fd7e51a7c chore(runtime): update deploy/Dockerfile to latest PHP/Node baseline (BIT-31720)
Paperclip-Issue: BIT-31720
2026-10-23 18:36:17 +01:00
spark ac932323c8 Merge pull request 'fix(webdav): PDF validation for WebDAV sync (BIT-26608)' (#5) from task/BIT-26608-webdav-pdf-validation into main 2026-07-15 01:37:27 +01:00
XikaandCursor 5bc5e0d889 fix(webdav): accept PDFs with leading bytes and JPEG-as-.pdf scans
WebDAV sync rejected valid files like 1784074260.pdf when the PDF magic
bytes were not at offset 0 (whitespace/BOM) or when a mobile scanner stored
JPEG bytes under a .pdf name. Scan the first 1KB for %PDF-, allow image
fallback for .pdf, and include validation detail in API errors.

Co-authored-by: Cursor <[email protected]>
2026-07-15 00:37:17 +00:00
spark bc39e00192 Merge pull request 'feat(imap): selectable folder sync per account (BIT-26607)' (#4) from task/BIT-26607-imap-folder-selection into main
Merge PR #4: feat(imap): selectable folder sync per account (BIT-26607)

BIT-26607 / BIT-26609
2026-07-15 01:35:23 +01:00
spark 91b1a726e8 Merge pull request 'feat(scrapers): Amazon & Temu invoice downloader + BizDocs upload (BIT-26279/BIT-26280)' (#3) from task/BIT-26279-invoice-downloader into main 2026-07-06 23:31:33 +01:00
9 changed files with 133 additions and 9 deletions

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
name: ci
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
verify:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: PHP 8.5 syntax check (webhook-receiver.php)
run: |
php -v
php -l deploy/webhook-receiver.php
- name: Setup Node.js 24.22.1
uses: actions/setup-node@v4
with:
node-version: "24.22.1"
- name: Build admin-ui
working-directory: admin-ui
run: |
npm ci
npm run build
+1
View File
@@ -0,0 +1 @@
24.22.1
+1 -1
View File
@@ -1,4 +1,4 @@
FROM node:20-alpine AS build
FROM node:24-alpine AS build
ARG GIT_SHA=unknown
WORKDIR /app
COPY package.json package-lock.json ./
+3
View File
@@ -23,5 +23,8 @@
"tailwindcss": "^3.4.14",
"typescript": "^5.6.3",
"vite": "^5.4.10"
},
"engines": {
"node": ">=24.22.1"
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
FROM php:8.3-cli-alpine
FROM php:8.5-cli-alpine
RUN apk add --no-cache bash git curl docker-cli docker-cli-compose
+56 -4
View File
@@ -12,6 +12,9 @@ MIN_PDF_BYTES = 1024
MIN_XML_BYTES = 80
MIN_ZIP_BYTES = 22
_PDF_MAGIC = b"%PDF-"
_PDF_HEADER_SCAN_BYTES = 1024
MIN_IMAGE_WIDTH = 200
MIN_IMAGE_HEIGHT = 200
@@ -124,12 +127,18 @@ def _image_meets_min_dimensions(data: bytes, ext: str) -> bool:
return True
def _find_pdf_magic(data: bytes) -> int | None:
"""Return byte offset of %PDF- within the header window, or None."""
if not data:
return None
index = data[:_PDF_HEADER_SCAN_BYTES].find(_PDF_MAGIC)
return index if index >= 0 else None
def _is_valid_pdf(data: bytes) -> bool:
if len(data) < MIN_PDF_BYTES:
return False
if not data.startswith(b"%PDF-"):
return False
return True
return _find_pdf_magic(data) is not None
def _is_valid_xml(data: bytes) -> bool:
@@ -199,7 +208,12 @@ def is_plausible_invoice_file(
return False
if ext == ".pdf" or content_type == "application/pdf":
return _is_valid_pdf(data)
if _is_valid_pdf(data):
return True
# Some mobile scanners store JPEG/PNG bytes under a .pdf filename.
if _is_valid_image(data, ".jpeg") or _is_valid_image(data, ".png"):
return True
return False
if ext == ".xml" or content_type in ("application/xml", "text/xml"):
return _is_valid_xml(data)
@@ -208,3 +222,41 @@ def is_plausible_invoice_file(
return _is_valid_zip(data)
return False
def invoice_validation_failure_reason(
data: bytes,
*,
filename: str,
content_type: str,
) -> str | None:
"""Human-readable reason when is_plausible_invoice_file would return False."""
if is_plausible_invoice_file(data, filename=filename, content_type=content_type):
return None
ext = _extension_from_filename(filename)
content_type = (content_type or "").lower()
if not data:
return "empty file"
if ext == ".pdf" or content_type == "application/pdf":
if len(data) < MIN_PDF_BYTES:
return f"too small ({len(data)} bytes, min {MIN_PDF_BYTES})"
if _find_pdf_magic(data) is None:
head = data[:16].hex()
return f"PDF header %PDF- not found in first {_PDF_HEADER_SCAN_BYTES} bytes (head={head})"
return "not a valid PDF or invoice scan image"
if ext in (".png", ".jpg", ".jpeg") or content_type.startswith("image/"):
if len(data) < MIN_IMAGE_BYTES:
return f"image too small ({len(data)} bytes, min {MIN_IMAGE_BYTES})"
return "image below minimum dimensions or invalid format"
if ext == ".xml" or content_type in ("application/xml", "text/xml"):
return "invalid or too small XML"
if ext == ".zip" or content_type in ("application/zip", "application/x-zip-compressed"):
return "invalid or too small ZIP"
return f"unsupported type ({ext or content_type or 'unknown'})"
+13 -2
View File
@@ -12,7 +12,10 @@ import smtplib
from forwarder.bizdocs.client import BizdocsClient, BizdocsCredentials, BizdocsSession
from forwarder.bizdocs.errors import BizdocsError
from forwarder.db.models import Account, DEFAULT_ALLOWED_EXTENSIONS, DeliveryMode
from forwarder.email.invoice_validation import is_plausible_invoice_file
from forwarder.email.invoice_validation import (
invoice_validation_failure_reason,
is_plausible_invoice_file,
)
from forwarder.email.parsing import InvoiceAttachment, collect_matching_attachments
from forwarder.email.smtp_client import SmtpConfig, create_smtp_client, forward_invoice_attachments
@@ -104,7 +107,15 @@ def deliver_invoice_file(
content_type = _content_type_for_filename(filename)
if not is_plausible_invoice_file(data, filename=filename, content_type=content_type):
raise ValueError(f"File {filename} failed invoice validation")
detail = invoice_validation_failure_reason(
data,
filename=filename,
content_type=content_type,
)
message = f"File {filename} failed invoice validation"
if detail:
message = f"{message}: {detail}"
raise ValueError(message)
if account.delivery_mode == DeliveryMode.api:
if bizdocs_session is None:
+27
View File
@@ -112,6 +112,33 @@ def test_accepts_valid_pdf_attachment():
assert len(collect_matching_attachments(msg)) == 1
def test_accepts_pdf_with_leading_whitespace():
pdf = b" \n\r\t" + b"%PDF-1.4\n" + (b"% invoice body\n" * 80)
assert is_plausible_invoice_file(
pdf,
filename="1784074260.pdf",
content_type="application/pdf",
)
def test_accepts_pdf_with_utf8_bom():
pdf = b"\xef\xbb\xbf%PDF-1.4\n" + (b"% body\n" * 150)
assert is_plausible_invoice_file(
pdf,
filename="scan.pdf",
content_type="application/pdf",
)
def test_accepts_jpeg_bytes_with_pdf_extension():
data = _fake_jpeg(800, 1200)
assert is_plausible_invoice_file(
data,
filename="1784074260.pdf",
content_type="application/pdf",
)
def test_rejects_truncated_pdf():
msg = _msg_with_part(
data=b"%PDF",
+1 -1
View File
@@ -1,5 +1,5 @@
# Build stage — compile the React admin UI
FROM node:20-alpine AS builder
FROM node:24-alpine AS builder
WORKDIR /build
COPY admin-ui/package*.json ./