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

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

Parked opened this
Closed without merging

A note or note list from the app's own origin now counts as a person's only if it carries the panel's one-use proof. Without a valid proof it is a visitor's, and admin is false. The tests I ran pass (apps-feedback, the toolbar and pill suites) and tsc is clean.

Notes

stopped parked by the crew deploy d784d74

opened this

A note or note list from the app's own origin now counts as a person's only if it carries the panel's one-use proof. Without a valid proof it is a visitor's, and admin is false. The tests I ran pass (apps-feedback, the toolbar and pill suites) and tsc is clean. I did not run the whole suite or bun scripts/design-lint.ts (nothing in src/web/ changed), and I did not exercise a real page load, because that needs a running app.

What changed

  • Proof module: src/apps/proof.ts issues and spends tokens. A token is bound to the grant cookie value and the host, is spent whether or not it matches, and is kept in memory as a hash with a one-hour life and a cap of 10,000.
  • Page load: in src/apps/proxy.ts, a signed-in person's page load gets the token in the panel's script tag as data-proof, and the page answers cache-control: private, no-store. This applies when Sec-Fetch-Dest is document, absent, or a cross-site iframe. A same-origin fetch of the page gets no token, and the token never goes in a URL.
  • Note endpoints: POST /__forge/note and GET /__forge/notes spend the proof from the x-forge-proof header. In src/apps/feedback.ts, with a valid proof the sender is @name, the list is theirs and admin is computed. Without one, or with a reused, foreign-grant or foreign-host token, the sender is visitor-…. A private or sealed app still opens its door to the grant holder but files an unproven note as a visitor.
  • Next token: every answer to a request with a valid proof carries the next token in x-forge-proof.
  • Panel script: src/apps/toolbar.ts strips data-proof from its tag on load. It sends notes and list requests one at a time through a small api helper, so the poll and a send cannot spend the same token, and it keeps each answer's next token.
  • Tests: test/apps-feedback.test.ts covers an unproven POST as a visitor, a proven one as @alice, and reused, foreign-grant, foreign-host and made-up tokens as visitors. The page-load rule (isPageLoad) and the data-proof tag are covered by unit tests rather than a real request, so the same-origin-fetch-gets-no-token case is not tested end to end. I also rewrote the private-app test to use a proof.
  • Existing tests edited: test/apps-crew-pill.test.ts and test/toolbar-actions.test.ts counted fetch( calls and the literal fetch("/__forge/note". Those two were wrong about the code's shape, since the notes now go through the api helper, so I updated them.

Left out

  • Tokens live in memory, so a forge restart means the open panel files as a visitor until the page is reloaded. Persisting them would be a table for little gain.
  • An app's own script could read data-proof from the tag before the panel strips it. The panel script is deferred, so this is a narrowing of the exposure, not a seal.

Try it by signing in, opening an app page and sending a note from the panel, which should come through as @you. Then run fetch('/__forge/note', …) from the page's console, which should come through as visitor-….

Closes #5354

commented

A note or note list from the app's own origin now counts as a person's only if it carries the panel's one-use proof. Without a valid proof it is a visitor's, and admin is false. The tests I ran pass (apps-feedback, the toolbar and pill suites) and tsc is clean. I did not run the whole suite or bun scripts/design-lint.ts (nothing in src/web/ changed), and I did not exercise a real page load, because that needs a running app.

What changed

  • Proof module: src/apps/proof.ts issues and spends tokens. A token is bound to the grant cookie value and the host, is spent whether or not it matches, and is kept in memory as a hash with a one-hour life and a cap of 10,000.
  • Page load: in src/apps/proxy.ts, a signed-in person's page load gets the token in the panel's script tag as data-proof, and the page answers cache-control: private, no-store. This applies when Sec-Fetch-Dest is document, absent, or a cross-site iframe. A same-origin fetch of the page gets no token, and the token never goes in a URL.
  • Note endpoints: POST /__forge/note and GET /__forge/notes spend the proof from the x-forge-proof header. In src/apps/feedback.ts, with a valid proof the sender is @name, the list is theirs and admin is computed. Without one, or with a reused, foreign-grant or foreign-host token, the sender is visitor-…. A private or sealed app still opens its door to the grant holder but files an unproven note as a visitor.
  • Next token: every answer to a request with a valid proof carries the next token in x-forge-proof.
  • Panel script: src/apps/toolbar.ts strips data-proof from its tag on load. It sends notes and list requests one at a time through a small api helper, so the poll and a send cannot spend the same token, and it keeps each answer's next token.
  • Tests: test/apps-feedback.test.ts covers an unproven POST as a visitor, a proven one as @alice, and reused, foreign-grant, foreign-host and made-up tokens as visitors. The page-load rule (isPageLoad) and the data-proof tag are covered by unit tests rather than a real request, so the same-origin-fetch-gets-no-token case is not tested end to end. I also rewrote the private-app test to use a proof.
  • Existing tests edited: test/apps-crew-pill.test.ts and test/toolbar-actions.test.ts counted fetch( calls and the literal fetch("/__forge/note". Those two were wrong about the code's shape, since the notes now go through the api helper, so I updated them.

Left out

  • Tokens live in memory, so a forge restart means the open panel files as a visitor until the page is reloaded. Persisting them would be a table for little gain.
  • An app's own script could read data-proof from the tag before the panel strips it. The panel script is deferred, so this is a narrowing of the exposure, not a seal.

Try it by signing in, opening an app page and sending a note from the panel, which should come through as @you. Then run fetch('/__forge/note', …) from the page's console, which should come through as visitor-….

commented

Parked by the crew: the check failed ("RepoSource: one repository, two places to read it from > a mirror reports its stages in order and ends holding the repo") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs