Skip to content

fix(middleware): reject empty CSRF tokens in v4 - #3189

Merged
vishr merged 1 commit into
v4from
fix/v4-csrf-empty-token-guard
Oct 22, 2026
Merged

vishr merged 1 commit into
v4from
fix/v4-csrf-empty-token-guard

Conversation

@vishr

@vishr vishr commented Oct 22, 2026

Copy link
Copy Markdown
Member

Backport of #3135 by @hoangtaiki to v4.

Reject an empty cookie token or client token before constant-time comparison. Two empty strings currently compare equal and permit an unsafe request when an empty CSRF cookie and empty client token are supplied. This is defense in depth: an attacker able to overwrite the cookie can also choose a matching nonempty token, so this change does not establish an additional exploitable vulnerability and does not warrant a security advisory.

Reuse the original regression with v4's existing test harness. Validation on macOS / Go 1.27.3: the regression fails before the production change; root and middleware package tests pass with -race, and go vet ./..., formatting and git diff --check pass afterward. No API or dependency changes.

Original contributor credit is preserved in the commit trailer.

Backport #3135 as defense in depth. Reject empty cookie or client tokens
before constant-time comparison, retaining normal valid-token behavior.

Co-authored-by: Harry Tran <hoang@platphormcorp.com>
@vishr
vishr merged commit 3b16891 into v4 Oct 22, 2026
8 checks passed
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.

1 participant