Public: anyone can read this; the crew can change it.

A note from the app's own origin is a visitor's unless it carries the forge panel's one-use proof #5597

Parked opened this
Closed without merging

A note or notes-list request from an app's own origin is now a visitor's unless it carries the panel's one-use proof. I never loaded a real proxied page: the token is issued in src/apps/proxy.ts, and neither that issuing nor the panel script's use of the token is exercised by a test.

Notes

stopped parked by the crew deploy 67f7e55

opened this

A note or notes-list request from an app's own origin is now a visitor's unless it carries the panel's one-use proof. I never loaded a real proxied page: the token is issued in src/apps/proxy.ts, and neither that issuing nor the panel script's use of the token is exercised by a test. test/apps-feedback.test.ts, test/toolbar-actions.test.ts, test/apps-crew-pill.test.ts, test/apps-toolbar.test.ts and test/apps-pill-where.test.ts pass, as does bun x tsc --noEmit. I did not run bun test as a whole; the forge's check does that.

What changed

  • Token store: the new src/apps/proof.ts issues and spends tokens. Each is random, bound to the grant cookie and the host, one-use, and expires after an hour.
  • Page load: src/apps/proxy.ts issues a token into the panel's script tag as data-proof. It does so only for a signed-in person's page load: Sec-Fetch-Dest document or absent, or an iframe with Sec-Fetch-Site: cross-site. That page answers cache-control: private, no-store. A same-origin fetch of the page gets no token.
  • Spending the token: src/apps/feedback.ts spends the x-forge-proof header on /__forge/note and /__forge/notes.
    • With a valid token, the note is @name and the list is theirs, with admin as before.
    • With no token, a reused one, or one for another grant or host, the note is visitor-…, the list is the visitor's and admin is false.
    • Every answer to a valid proof carries the next token in x-forge-proof.
  • Panel: src/apps/toolbar.ts removes data-proof from its tag on load and keeps the token in a closure. Notes-door calls go through one queue, so each spends the token and picks up the next. The token is never put in a URL. The panel script is a src= tag, so there is no inline script and no nonce was needed.
  • Tests: test/apps-feedback.test.ts covers an unproven post, a proven one, a reused token, a foreign-grant token, a foreign-host token, and pageLoad refusing a same-origin fetch. It also checks the tag attribute and that the script strips it.

Changed existing tests

  • The two tests that posted as a signed-in person with a grant cookie alone now send a proof, because a bare grant cookie is a visitor's by design.
  • Two tests counted fetch( calls in the panel script, which dropped from 3 to 2 once the notes calls went through one door() function. I updated the counts and one string match.

Left out

  • Proofs live in memory, so a restart makes open panels visitors until the page reloads. I left it there to avoid a table, and the cost is one reload.
  • A sealed preview or private app now answers 404 to an unproven notes request, since it admits only people.

Try it by loading a signed-in app page, opening the panel and sending a note, which should come back as @you. A curl with the grant cookie but no x-forge-proof gets visitor-….

Closes #5395

commented

A note or notes-list request from an app's own origin is now a visitor's unless it carries the panel's one-use proof. I never loaded a real proxied page: the token is issued in src/apps/proxy.ts, and neither that issuing nor the panel script's use of the token is exercised by a test. test/apps-feedback.test.ts, test/toolbar-actions.test.ts, test/apps-crew-pill.test.ts, test/apps-toolbar.test.ts and test/apps-pill-where.test.ts pass, as does bun x tsc --noEmit. I did not run bun test as a whole; the forge's check does that.

What changed

  • Token store: the new src/apps/proof.ts issues and spends tokens. Each is random, bound to the grant cookie and the host, one-use, and expires after an hour.
  • Page load: src/apps/proxy.ts issues a token into the panel's script tag as data-proof. It does so only for a signed-in person's page load: Sec-Fetch-Dest document or absent, or an iframe with Sec-Fetch-Site: cross-site. That page answers cache-control: private, no-store. A same-origin fetch of the page gets no token.
  • Spending the token: src/apps/feedback.ts spends the x-forge-proof header on /__forge/note and /__forge/notes.
    • With a valid token, the note is @name and the list is theirs, with admin as before.
    • With no token, a reused one, or one for another grant or host, the note is visitor-…, the list is the visitor's and admin is false.
    • Every answer to a valid proof carries the next token in x-forge-proof.
  • Panel: src/apps/toolbar.ts removes data-proof from its tag on load and keeps the token in a closure. Notes-door calls go through one queue, so each spends the token and picks up the next. The token is never put in a URL. The panel script is a src= tag, so there is no inline script and no nonce was needed.
  • Tests: test/apps-feedback.test.ts covers an unproven post, a proven one, a reused token, a foreign-grant token, a foreign-host token, and pageLoad refusing a same-origin fetch. It also checks the tag attribute and that the script strips it.

Changed existing tests

  • The two tests that posted as a signed-in person with a grant cookie alone now send a proof, because a bare grant cookie is a visitor's by design.
  • Two tests counted fetch( calls in the panel script, which dropped from 3 to 2 once the notes calls went through one door() function. I updated the counts and one string match.

Left out

  • Proofs live in memory, so a restart makes open panels visitors until the page reloads. I left it there to avoid a table, and the cost is one reload.
  • A sealed preview or private app now answers 404 to an unproven notes request, since it admits only people.

Try it by loading a signed-in app page, opening the panel and sending a note, which should come back as @you. A curl with the grant cookie but no x-forge-proof gets visitor-….

commented

Parked by the crew: the check failed ("the merge queue > a gate that never answers is abandoned at the deadline, and the next sweep lands (#3430)") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs