Skip to content

feat(forms): confirmation can show opted-in submitted fields (#527) - #700

Merged
jimhoyd merged 1 commit into
mainfrom
feat/forms-confirmation-fields
Sep 25, 2026
Merged

jimhoyd merged 1 commit into
mainfrom
feat/forms-confirmation-fields

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Fixes #527

What

A forms flow can opt submitted fields into its confirmation page:

confirmation:
  title: Thank you
  message: We will reply to {email} about {topic}.
  show: [email, topic]
  • confirmation.show lists the fields to show. The message can place any of them inline as a {field} placeholder. Listed fields that the message does not use follow as a <dl> of label and value. A checkbox reads Yes/No and a select shows its option label. A field that is not listed never leaves the POST.
  • Startup refuses a show entry that is not a declared field, and a {field} placeholder whose field is not in show. Placeholders use the field-name grammar [a-z][A-Za-z0-9_]*, so any other braces stay literal text. I added no restriction by field type: every admitted value is already bounded and escaped, the vocabulary has no password or secret input type, and show is the author's explicit allowlist.
  • Every value is HTML-escaped. Placeholders are filled in one pass after the message is escaped, so a value cannot add markup or another placeholder (tested with a {email}-bearing value).
  • The confirmation always sends Cache-Control: no-store. The extension sets it explicitly, and core's privacy floor also forces it.
  • The onSubmit contract is unchanged. The handoff is issued only after onSubmit succeeds.

Handoff design and why

The handoff is a stateless sealed cookie, __Host-urlcode-forms-confirmation (Path=/; Secure; HttpOnly; SameSite=Strict; Max-Age=300), set on the 303:

  • Cipher: AES-256-GCM with a random 96-bit nonce. The key is derived from the host's forms CSRF secret with HKDF-SHA256 (info urlcode-forms-confirmation-v1), which keeps it separate from the secret's HMAC use for CSRF tokens. GCM's tag provides the authentication that an HMAC would, and the encryption means values are never readable in the cookie.
  • Binding: the flow name and the caller's __Host-urlcode-forms-csrf binding cookie are GCM associated data. A handoff sealed for another flow or another browser, or with no binding cookie, does not decrypt.
  • Payload: only the show values and an expiry. The plaintext is capped at 2 KiB of JSON. Above the cap no handoff is issued, and the page renders the fixed form.
  • Not in-memory state: forms targets node, aws and vercel, where the confirmation GET can reach a different instance than the POST.
  • Why __Host-: it rules out a sibling subdomain setting the cookie, which a path-scoped __Secure- cookie cannot guarantee. The value is ciphertext, so sending it on other paths of the same origin exposes nothing.
  • Fallback: a missing, expired, tampered, other-flow or other-browser handoff renders the fixed confirmation with no values and no error. Placeholders render as nothing.
  • Read behaviour: GET clears the cookie (Max-Age=0) whether or not it opened, so a refresh shows the fixed page. HEAD answers with the fixed page and leaves the cookie in place.

Limitation, documented in packages/forms/SECURITY.md: clearing happens in the browser, so this is not server-enforced single use. Within its 5 minutes, only the same browser, holding both HttpOnly cookies, could present it again.

Tests (packages/forms/test/forms.test.ts)

  • Shown values render escaped, placeholders are substituted, a select shows its label and a checkbox shows Yes, a value is not re-expanded, unlisted fields never appear, and the redirect URL carries no values.
  • The cookie carries no plaintext, its attributes are pinned, the page is no-store, the cookie is cleared on read, and a refresh shows the fixed page.
  • These render the fixed page: another browser's binding cookie, a missing binding cookie, a tampered or junk cookie, the other flow's confirmation, an expired handoff (mocked Date), and an oversized handoff (not issued).
  • HEAD does not consume the handoff.
  • Startup refuses an unknown show field and a placeholder that is not in show, including when show is absent. Literal braces are accepted.

Docs

  • Forms README.md: new section "Showing submitted values on the confirmation".
  • Forms SECURITY.md: new "Confirmation values" section.
  • Forms CHANGELOG.md (Unreleased) and llms.txt.
  • docs/EXTENSIONS.md and docs/FRAMEWORK.md: wording changed from "fixed confirmation".
  • urlcode.json regenerated with npm run build:addons.
  • No RIM card exists for forms, and YAML-REFERENCE.md does not cover extension config.

Verification

  • npm run typecheck: pass
  • forms tests: 19/19 pass (4 new)
  • npm run verify: exit 0 (core 798/798; workspace suites all pass; build-addon-manifest --check clean; llms-full.txt regenerated with npm run docs:llms)
  • npm run test:package: exit 0 (package audit plus packed installation and starter/cookbook smoke)

CI passing is not an independent security review.

🤖 Generated with Claude Code

confirmation.show lists fields to show on the confirmation page, and the
message may place them as {field} placeholders. Values reach the page in
an AES-256-GCM sealed __Host- cookie (HKDF key from the CSRF secret, flow
and CSRF binding cookie as associated data, 5-minute expiry, 2 KiB cap,
cleared on read). Anything else renders the fixed page. Startup refuses
undeclared show fields and placeholders not listed in show.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd force-pushed the feat/forms-confirmation-fields branch from e78be61 to 7565db7 Compare September 25, 2026 00:21
@jimhoyd
jimhoyd merged commit 17f4a13 into main Sep 25, 2026
23 checks passed
@jimhoyd
jimhoyd deleted the feat/forms-confirmation-fields branch September 25, 2026 00:25
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.

[Gap]: forms confirmation cannot safely show opted-in submitted fields

1 participant