Skip to content

Audit follow-ups: sealed reports, formula-safe CSV, partial claims said plainly - #47

Merged
todortodorovic merged 1 commit into
mainfrom
fix/audit-reports-and-partial
Nov 16, 2026
Merged

todortodorovic merged 1 commit into
mainfrom
fix/audit-reports-and-partial

Conversation

@todortodorovic

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes four findings from the security audit of e7073ffc:

  • #11374: daily reports were uploaded to the public Bulletin chain unencrypted when no key was set.
  • #11379: the report key was a single unsalted SHA-256, and a public fingerprint let anyone check passphrase guesses offline.
  • #11369: the CSV export did not neutralise cells that a spreadsheet runs as formulas.
  • #11383: a partial coins claim was shown as "Payment received".

It completes the audit plan, together with #41 (Voucher mode removed) and #42 (CI / supply chain). The report index contract findings (#11364 / #11386) are deferred. The app does not use the contract while the admin-QR binding is retired.

Reports (#11374, #11379)

  • No upload without a key.
    • The report job checks for a key before any work, and does not fall back to uploading plaintext.
    • The unused uploadReport path, which uploaded plaintext, is removed.
    • uploadDailyReport now only accepts a sealed envelope.
  • v3 envelope.
    • The key is scrypt(passphrase, random 16-byte salt, N=2^15, r=8, p=1). The salt and parameters are stored in the envelope.
    • The old 32-bit fingerprint of an unsalted key is no longer written.
    • A keyCheck value derived from the salted key lets the app still tell a wrong key from a damaged copy. Testing a guess against it costs one scrypt, the same as against the AEAD tag.
    • A reader rejects an envelope that asks for a scrypt cost above N=2^17.
  • v2 reports still open, and still name the key they need.
  • Passphrase rule.
    • A new passphrase needs at least 12 characters.
    • Undo after Clear still restores an older, shorter passphrase, so the reports sealed under it stay readable.
    • Settings now says "No key set — reports can't be saved until you set one".

CSV export (#11369)

  • Both exports now use one escaper, csvCell in lib/export/csv.ts. The daily-reports page drops its own copy.
  • A text cell that starts with =, +, -, @, tab or CR gets a leading apostrophe, so a spreadsheet shows it as text instead of running it.
  • Plain numbers such as -5.00 stay numbers.

Partial coins claim (#11383)

  • The completed screen says "Partial payment", on a warning burst with an alert badge, instead of the success screen.
  • It states what is missing, for example: "Not paid in full: 7.50 CASH is missing. Only 5.00 of 12.50 CASH arrived."
  • Telemetry records outcome: "partial" instead of success.

Behaviour changes to know

  • A merchant who never set a report key cannot save a report until they set one. The report screens are still only reachable through the becomeMerchant flag or a direct URL.
  • For a v3 report, the wrong-key message no longer names the key's fingerprint. Not publishing that fingerprint is the fix for #11379.
  • scrypt adds roughly 0.1–0.5 s to each report save and open. I have not measured it on a phone.

Test plan

  • tsc --noEmit
  • vitest: 207 passed, including new report-crypto and csv-export tests and a test for the partial telemetry outcome
  • eslint, 0 errors
  • next build
  • check:tokens, count unchanged
  • Full Playwright e2e suite: 133 passed
    • Report specs now set a report key and decrypt the uploaded v3 envelope in Node.
    • New specs cover the save being refused without a key and a short passphrase being rejected.
    • The partial-claim spec checks the new title and copy.
  • Measure scrypt time on a device: report save and open on Android.

🤖 Generated with Claude Code

…id plainly

Findings 11369, 11374, 11379 and 11383 from the security audit of
e7073ff.

Reports (11374, 11379)
- A report is never uploaded without a key. Bulletin is public and
  permanent, so the job refuses up front instead of falling back to
  plaintext, and the unused uploadReport path (plaintext) is gone.
  uploadDailyReport takes only a sealed envelope.
- New reports are v3 envelopes: key = scrypt(passphrase, random 16-byte
  salt, N=2^15 r=8 p=1), salt and parameters in the envelope. The public
  32-bit fingerprint of an unsalted SHA-256 key is no longer written; a
  salted key check tells a wrong key from a damaged copy instead. Readers
  cap the scrypt cost an envelope may ask for.
- Legacy v2 reports still open (and still name the key they need).
- A new passphrase needs at least 12 characters. Undo after Clear puts
  back an older, shorter phrase so its reports stay readable.

CSV export (11369)
- One escaper for both exports. A text cell starting with = + - @ tab or
  CR gets a leading apostrophe so a spreadsheet shows it instead of
  running it; plain numbers such as -5.00 stay numbers. The daily-reports
  page drops its own copy.

Partial coins claims (11383)
- The completed screen says "Partial payment" on a warning burst with an
  alert badge, and names what is missing: "Not paid in full: 7.50 CASH is
  missing. Only 5.00 of 12.50 CASH arrived."
- Telemetry records outcome "partial", not "success".

Checked: tsc, vitest (207), eslint, next build, the full e2e suite (133
passed), check:tokens unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

pr47-terminal.paseo · logs

https://pr47-terminal.paseo.li

@todortodorovic
todortodorovic merged commit 8d1a460 into main Nov 16, 2026
5 checks passed

This branch was successfully deployed

1 active deployment
preview — 30dfd3d1 Deployed Nov 16, 2026 by todortodorovic via deploy #80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant