Files
faunosteo/.claude/tasks/contracts/2026-10-11-step-06-security-fix-2.md

18 lines
2.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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
1. `packages/pdf/src/render/linkAnnotation.ts` writes `URI: PDFHexString.of(<hex of the ASCII bytes>)`; a test asserts the saved bytes contain the hex form of `https://faunosteo.com` (uppercase or lowercase hex, no `FEFF`), that a reload through pdf-lib decodes `/URI` to the URL, and that the injection payload (cast past the schema) still yields no `/JavaScript`, `/Next` or `/JS` in 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 .* passed
2. `packages/pdf/src/branding.ts` `pngHeaderIssue` walks chunks (length, type, data, CRC) until `IEND` or the end of the buffer: first chunk must be `IHDR` with length 13; any further `IHDR`, or `acTL`/`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 with `acTL` refused, truncated chunk length refused, the four real `public/` logos and the two fixture PNGs accepted; the export-level test asserts a doubled-IHDR header logo gives exactly `[{ kind: 'logo_failed', slot: 'headerLogo' }]` and `embedPng` never receives it.
3. `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.
4. 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.