fix: prevent nil pointer panic in WAF detector#6368
Conversation
- Add nil checks for detector and regexCache in DetectWAF() - Add nil check for individual regex entries before MatchString() - Add comprehensive unit tests for nil pointer scenarios - Prevents runtime panic when WAF detector encounters nil pointers during regex matching
WalkthroughNil pointer safety was added to the Changes
Sequence Diagram(s)sequenceDiagram
participant Tester
participant WafDetector
Note over Tester: Call DetectWAF with possible nils
Tester->>WafDetector: DetectWAF(content)
alt WafDetector or regexCache is nil
WafDetector-->>Tester: return ("", false)
else regexCache has nil regex
WafDetector-->>Tester: skip nil, continue
else regex matches
WafDetector-->>Tester: return (name, true)
else no match
WafDetector-->>Tester: return ("", false)
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🧰 Additional context used🧠 Learnings (2)📓 Common learnings📚 Learning: the user dwisiswant0 declined adding documentation for internal api changes in pkg/fuzz/component/pa...Applied to files:
🔇 Additional comments (4)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
@coderabbitai |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chainI'll create an issue to document the nil pointer panic that was occurring in the WAF detector. Let me create this issue with the stack trace you provided. @knakul853 I've created an issue to document the nil pointer panic that was occurring in the WAF detector. The issue includes the stack trace you provided and references this PR as the fix. The issue has been assigned to you as requested. 🏁 Script executed: Length of output: 1328 @knakul853 Perfect! I've successfully created issue #6369 to document the nil pointer panic in the WAF detector: #6369 The issue includes:
This will serve as proper documentation for the panic that was occurring before your fix. 🧠 Learnings used |
Proposed changes
Checklist
Summary by CodeRabbit
Bug Fixes
Tests