You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: forms CSRF token is not bound to the caller and tests do not reach the forged-token path #468
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
fix(forms): bind CSRF token to the caller and add domain separation
fix(forms): bind CSRF token to the caller and add domain separation