Skip to content

[Bug]: forms CSRF token is not bound to the caller and tests do not reach the forged-token path #468

Closed

Description

@jimhoyd

Runtime revision and environment

main at d939969 (static source review; not executed against a deployment). Node/OS/deployment: not applicable.

Minimal reproduction

Reported by review, not independently reproduced. Exploit-level detail is intentionally omitted per SECURITY.md. Malformed-token handling in verifyHmac is being fixed in a separate PR and is out of scope here.

CSRF admission in packages/forms/src/forms.ts (lines 44-45 token helpers, and the Origin check in createFormsExtension from line 56):

  • Token not bound to the caller. The signed payload is only {flow} plus expiry. It is not tied to a session or cookie, so any token minted for the flow is valid for any caller until the TTL.
    • Fix: bind the token to a per-browser cookie (double-submit) or to the session when auth: true.
  • Reusable within the TTL.
    • Fix: accept that explicitly in docs, or add a single-use nonce if replay matters for the flow.
  • No domain-separation prefix on the signed data shared with other createSignedToken users.
    • Fix: include a purpose string such as urlcode-forms-csrf in the signed payload.
  • Absent Origin is accepted.
    • Fix: fall back to Sec-Fetch-Site / Referer when Origin is absent, or refuse, and document the choice.

Test coverage:

  • The test titled "refuses missing or forged CSRF…" (packages/forms/test/forms.test.ts:43) sends a missing token but no well-formed forged or cross-flow token.
  • The only csrf=forged post (line 56) targets a protected mount, where the auth gate answers 401 before forms runs.
  • There is no test of onSubmit.
  • Fix: add those cases to an unprotected mount.

Minor: fail() in forms.ts:42 takes a fields parameter that no caller passes. Remove it.

Activity

  1. added
    bug
    extension
    on Sep 22, 2026
  2. added 2 commits that reference this issue on Sep 22, 2026
    25c2047
    3624ff9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugextension

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions