📑 feat: Add Standalone File Extraction Service - #306
lia-by-librechat[bot] wants to merge 8 commits into
Conversation
|
Head: Standalone PDF/DOCX extraction service with bounded binary transport, structured text, restricted request-local workers, and a hardened Compose recipe. No Local typecheck, build, formatting, lifecycle tests, and container qualification passed before publication. Frozen-head checks are running alongside CI. |
|
Head: Independent-review findings:
Added native isolation and nested-table regressions. PDF bounds now cover uncompressed streams and intermediate inflation buffers. Container qualification uses invocation-scoped resources. Focused checks and CI are running for this head. |
|
Head:
Local checks passed: formatting, no-emit typecheck, build, 13 focused tests, real PDF/DOCX extraction, 19 adversarial fixtures, hardened Compose isolation, cancellation, cleanup and restart. Fresh independent review and CI cover this head. |
|
@codex review the latest head, final review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Head: Fixed both P2 DOCX findings: unsupported content-control/body wrappers now fail explicitly; XML validation follows OPC content types, including renamed parts. Prior worker-control, nested-table and PDF policy findings remain fixed. Local checks passed: scoped formatting, no-emit typecheck/build, 14 focused tests, real document extraction and 30 adversarial fixtures, hardened Compose qualification, cancellation, cleanup and restart. No documentation changes remain in the PR. Deployment, protocol and boundary details are in its description. Fresh exact-head review and CI are running. |
|
Head: Fixed the P2 remaining-run-wrapper finding with a closed DOCX content grammar. Direct paragraphs/tables/runs/hyperlinks and known text primitives are supported; other content structures fail explicitly. Positive fixtures preserve formatting-adjacent text, links, tabs and breaks. Standard and unknown wrapper regressions pass. Local verification passed: formatting, no-emit typecheck/build, 14 focused tests, 44 adversarial endpoint fixtures and hardened Compose isolation/lifecycle qualification. All earlier findings remain fixed. Fresh independent review and CI cover this head. |
|
Head: Fixed the P2 merged-cell finding. DOCX traversal consumes physical cells once and preserves grid placeholders. Horizontal, vertical, rectangular, nested and 600-KiB merged-cell cases pass. Invalid continuations/spans, hidden continuation content, legacy merges and excessive table width fail explicitly. Local verification passed: formatting, no-emit typecheck/build, 14 focused tests, 49 adversarial endpoint fixtures and hardened Compose qualification. Prior findings remain fixed. Fresh independent review and CI cover this head. |
|
Head: Fixed the P2 PDF font-mapping finding. Used text operands require interpretable, complete mappings before decoding; unknown glyphs, missing fonts, incomplete Unicode maps, malformed codecs and unsupported graphics-state font selection fail explicitly. Real valid Unicode/ligature/emoji/composite/Form cases pass. Local verification passed: scoped formatting, no-emit typecheck/build, 14 focused tests, 63 adversarial endpoint fixtures and shipped hardened Compose isolation/lifecycle qualification. All earlier findings remain fixed. Fresh independent review and CI cover this head. |
|
Head: Fixed the P2 null-encoding finding. Direct/indirect null optional font entries are normalized to absence; non-core fonts need an effective standard encoding or complete character map. Type1/TrueType null/absent/empty-dictionary regressions and valid core/null/Unicode cases pass. Local verification passed: formatting, no-emit typecheck/build, 14 focused tests, 75 adversarial endpoint fixtures and shipped hardened Compose isolation/lifecycle qualification. All earlier findings remain fixed. Fresh independent review and CI cover this head. |
|
Head: Independent exact-head review complete: no findings. Source and focused boundary checks covered this head; the reviewer did not rerun native parser/container qualification. All 12 CI checks pass. Local verification: scoped formatting, no-emit typecheck/build, 14 focused tests, real PDF/DOCX extraction with 75 adversarial fixtures, and shipped hardened Compose isolation/cancellation/cleanup/restart qualification passed.
No rejected or outstanding findings. Earlier incomplete review is not counted as clean. Qualified locally on Linux x86_64 with Landlock ABI 3+, Docker 29.8.2, Node 24.16.0 and Python 3.13.16. ARM, Docker Desktop and other runtime recipes remain unqualified. Private researcher reproduction was unavailable. No application routing, |
Scope
Standalone PDF/DOCX extraction microservice with its own package, image and Compose recipe. No existing code-api server,
/exec, LibreChat or RAG API changes. No AWS, Redis, S3, Kata or gVisor dependency.binary request → parser-free supervisor → restricted request-local worker → validated structured text → cleanup → responsePDF returns ordered, one-based page segments. Used fonts must have interpretable mappings; Type3/composite fonts require complete Unicode maps. Null optional encoding entries are treated as absent; non-core fonts without a usable standard or Unicode map fail closed. Unknown glyph names, missing fonts, incomplete maps and codec recovery or graphics-state font selection fail with
UNSUPPORTED_ENCODING. DOCX returns ordered body paragraphs and tables, including nested tables. Merged-cell text is extracted once, with tab placeholders retaining grid positions. Only a closed body grammar of paragraphs, tables, direct runs/hyperlinks and known text primitives is supported. Other content structures, fields, inline images and wrappers returnUNSUPPORTED_CONTENT, never successful partial text. Formatting is ignored. OCR, spreadsheets, headers/footers, text boxes, images and previews are not advertised. Authorization, policy, identity, chunking, embeddings, rollback and persistence remain caller-owned.Deployment
Requires Linux with Landlock ABI 3+ (normally kernel 6.2+) and Docker's default seccomp profile. The shipped non-root, read-only, capability-free container has no network. Share only its socket volume with the caller, read-only; caller GID 10001 authorizes socket access. No application storage, credentials or Docker socket mounts.
Each parser is a fresh restricted subprocess, not a disposable container/VM. Landlock limits file access to its job and packaged runtime; an additional seccomp filter blocks networking, process creation, process control and IPC. Workers receive no inherited application environment or descriptors. Container and host kernel are shared; kernel exploits, side channels and container-wide OOM are outside the boundary. No privileged mode, relaxed isolation or unsafe fallback.
API and limits
GET /v1/capabilitiesadvertises version, formats, structure and limits.POST /v1/extract-text: raw bytes withContent-Type: application/octet-stream, exactContent-Length,X-Extraction-Version: 1, andX-Extraction-Format: pdf|docx.{kind,index,text}segments. No base64 or upload/download workflow.Malformed, encrypted, empty and unsupported-encoding documents return safe error codes, not repaired/partial text or raw parser errors. ZIP inflation is measured independently of forged size/CRC metadata. Cancellation/deadlines kill workers and wait for close; scratch cleanup precedes success. Admission remains held through response delivery. Cleanup failure quarantines the backend. Missing isolation/dependencies prevent startup.
Verification
Run
npm ci --ignore-scripts,npm run format:check,npm run typecheck,npm test, andnpm run test:containerinpackages/extraction.Not qualified: ARM, Docker Desktop or other runtime recipes. Private researcher reproduction was unavailable. No application routing or LibreOffice re-enablement is included.