🐛 fix(csrf): port CORS subdomain match fixes - #4455
Conversation
The subdomain.match() in middleware/csrf/helpers.go was identical to the CORS one but missed two security fixes applied on 2026-06-18 to middleware/cors/utils.go: - bae48f0: reject empty wildcard labels via strings.HasSuffix(sub, ".") - 1b961aa: validate origins with normalizeOrigin() before matching This brings the CSRF subdomain matcher to parity with CORS and adds the corresponding regression tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QaVJcHsCGZBkYcSP9GhCU7
CORS normalizeOrigin rejects origins containing userinfo (parsedOrigin.User != nil), but the CSRF copy did not, silently stripping credentials and treating http://user:pass@example.com as a valid http://example.com. Port the guard and its test. Also add regression cases to both CORS and CSRF subdomain.match suites covering userinfo-bearing and non-normalized (uppercase) origins. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QaVJcHsCGZBkYcSP9GhCU7
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
💤 Files with no reviewable changes (3)
WalkthroughThe PR tightens CSRF origin validation, updates CORS subdomain test coverage, and removes CSRF storage manager pooling and msgp scaffolding. ChangesOrigin normalization and matching
CSRF storage manager cleanup
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4455 +/- ##
==========================================
+ Coverage 91.62% 91.64% +0.01%
==========================================
Files 134 134
Lines 13500 13487 -13
==========================================
- Hits 12370 12360 -10
+ Misses 721 719 -2
+ Partials 409 408 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Both unexported helpers had zero production callers and were referenced only by their own tests. subdomain.match now relies on normalizeOrigin instead of matchScheme, and normalizeDomain was never wired into the middleware. Remove the functions and their Test_MatchScheme / Test_NormalizeDomain tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QaVJcHsCGZBkYcSP9GhCU7
storageManager.pool was initialized but never Get/Put. Its only purpose was producing *item values, and the empty item struct existed solely to feed that pool. Removing pool makes item dead, which in turn makes its generated msgp serialization code (storage_manager_msgp.go and its test) dead. Drop the pool field, the item type, the msgp generate directives, the now-unused sync import, and the two generated files. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QaVJcHsCGZBkYcSP9GhCU7
The subdomain.match() in middleware/csrf/helpers.go was identical to the
CORS one but missed two security fixes applied on 2026-06-18 to
middleware/cors/utils.go:
This brings the CSRF subdomain matcher to parity with CORS and adds the
corresponding regression tests.