2.8 KiB
2.8 KiB
CONTRACT — step-06 security fix 2 (after re-audit PASS with 2 MEDIUM)
- date: 2026-10-11 | flow: ship-feature (executor, security loop) | branch: feature/step-06-pdf-archives
- status: active
REQUEST (IMMUTABLE)
Close the two MEDIUM findings of the second audit without changing any page output: (1) the /URI written as PDFHexString.fromText is UTF-16BE with a BOM, so poppler-based viewers read a dead link (þÿ…); write the URL's ASCII bytes as a hex string instead, keeping the injection protection; (2) the PNG budget reads only the first IHDR while UPNG honours the last one: walk the chunk list, require exactly one IHDR (length 13) as the first chunk, refuse any later IHDR and the APNG chunks acTL, fcTL, fdAT.
ACCEPTANCE CRITERIA
packages/pdf/src/render/linkAnnotation.tswritesURI: PDFHexString.of(<hex of the ASCII bytes>); a test asserts the saved bytes contain the hex form ofhttps://faunosteo.com(uppercase or lowercase hex, noFEFF), that a reload through pdf-lib decodes/URIto the URL, and that the injection payload (cast past the schema) still yields no/JavaScript,/Nextor/JSin the bytes. A character above 0x7e in the URL throws (the schema already refuses it) — test. CHECK: cd packages/pdf && corepack pnpm vitest run tests/security.test.ts tests/goldens.test.ts 2>&1 | grep -E "Tests " | tail -1 EXPECT: Tests .* passedpackages/pdf/src/branding.tspngHeaderIssuewalks chunks (length, type, data, CRC) untilIENDor the end of the buffer: first chunk must beIHDRwith length 13; any furtherIHDR, oracTL/fcTL/fdAT, or a chunk length that overruns the buffer → issue; the existing side/pixel caps stay. Tests: doubled IHDR (1×1 then 10000×10000) refused, APNG withacTLrefused, truncated chunk length refused, the four realpublic/logos and the two fixture PNGs accepted; the export-level test asserts a doubled-IHDR header logo gives exactly[{ kind: 'logo_failed', slot: 'headerLogo' }]andembedPngnever receives it.docs/PDF-FORMAT.md: the PNG sentence says the chunk list is walked and a second IHDR or APNG chunk is refused (replace any "never decoded" wording); "Known limits" names the browser rasterizer (apps/app/src/pdf/browserRasterizer.ts) as the production path whose<use>expansion limits are not measured.- Green from the root:
corepack pnpm typecheck && corepack pnpm lint && corepack pnpm test:run;git diff --quiet 8b86b92 HEAD -- apps/app/tests/fixtures/goldens(goldens untouched); link goldens still pass in both packages (the readers decode hex strings).
FILE SCOPE
packages/pdf/src/render/linkAnnotation.ts, packages/pdf/src/branding.ts, packages/pdf/tests/security.test.ts (and tests/helpers if a reader needs the ASCII-hex form), docs/PDF-FORMAT.md. Nothing else.