🐛 bug: validate nested CSRF extractor chains - #4439
Conversation
|
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 (2)
✅ Files skipped from review due to trivial changes (2)
WalkthroughThe PR adds ChangesExtractor Introspection, Cycle Detection, and CSRF Validation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 #4439 +/- ##
==========================================
+ Coverage 91.59% 91.60% +0.01%
==========================================
Files 134 134
Lines 13518 13537 +19
==========================================
+ Hits 12382 12401 +19
Misses 722 722
Partials 414 414
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:
|
Add a maxExtractorChainDepth guard to isInsecureCookieExtractorRecursive so a malformed or excessively nested extractor chain cannot cause unbounded recursion during config validation. Addresses PR review feedback requesting a cycle guard before recursing through Extractor.Chain. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QQriv9giBatSfqzmUr5aUj
| // terminates without panicking. | ||
| deep := extractors.FromHeader("X-Csrf-Token") | ||
| for range maxExtractorChainDepth + 50 { | ||
| for range 150 { |
There was a problem hiding this comment.
This should be a package const
Motivation
extractors.Chain(...)can hide a fallbackFromCookieextractor that reads the same cookie used for CSRF token storage, causing the double-submit check to compare a cookie to itself.extractors.Extractortype (which includesFromCookie) while the existing validation only inspected one chain level, leaving nested cookie fallbacks unchecked.Description
isInsecureCookieExtractorRecursiveand use it when validating chained extractors inmiddleware/csrf/config.goso nestedChainentries are checked transitively.validateExtractorSecuritywith the recursive check so any nested cookie extractor matchingCookieNametriggers a panic.InsecureNestedChainedExtractortomiddleware/csrf/config_test.gothat constructs a nestedChain(..., Chain(..., FromCookie("csrf_")))and asserts the configuration normalization panics.Testing
go test ./middleware/csrf -run 'Test_CSRF_ExtractorSecurity_Validation'and it passed (ok github.com/gofiber/fiber/v3/middleware/csrf).make testand all tests passed (3645 tests run, 2 skipped).make generate,make betteralign,make format, andmake lintand they completed successfully.make auditwhich failed due togovulncheckfindings in the local Go 1.25.1 standard library (the scan reported 25 standard-library vulnerabilities); this is an environment/toolchain issue and not a regression introduced by these changes.