-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
set headers for fuzzing request #5988
base: dev
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request introduces a new method Changes
Assessment against linked issues
Poem
Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/protocols/http/request_fuzz.go (1)
Line range hint
65-121
: Consider enhancing header management architectureWhile the centralization of header management is a good step, consider these architectural improvements:
- Create a dedicated header management component that can:
- Implement different header merging strategies
- Enforce security policies
- Provide audit logging
- Add configuration options for header handling behavior
- Consider implementing header policies through middleware
This would make the header management more flexible and secure while maintaining the current simplicity.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pkg/protocols/http/request_fuzz.go
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Tests (windows-latest)
🔇 Additional comments (2)
pkg/protocols/http/request_fuzz.go (2)
98-98
: LGTM!The placement of header addition after User-Agent setup and before request execution is correct.
65-65
: Consider header merging strategyThe current implementation overwrites any existing headers in the base request. Consider if certain headers from the original request should be preserved or merged instead of being overwritten.
Let's verify the impact on security-critical headers:
func (request *Request) addHeadersToRequest(baseRequest *retryablehttp.Request) { | ||
for k, v := range request.Headers { | ||
baseRequest.Header.Set(k, v) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add header validation and security controls
The current implementation could benefit from additional security controls:
- Validate header names and values to prevent header injection
- Consider protecting security-critical headers (e.g., Authorization, Cookie)
- Add logging for security-sensitive header modifications
Here's a suggested implementation:
func (request *Request) addHeadersToRequest(baseRequest *retryablehttp.Request) {
+ // List of headers that require special handling
+ sensitiveHeaders := map[string]bool{
+ "Authorization": true,
+ "Cookie": true,
+ "Origin": true,
+ }
+
for k, v := range request.Headers {
+ // Basic validation
+ if k == "" || strings.Contains(k, "\n") || strings.Contains(v, "\n") {
+ continue
+ }
+
+ // Log modifications to sensitive headers
+ if sensitiveHeaders[k] {
+ gologger.Debug().Msgf("Modifying sensitive header: %s", k)
+ }
+
baseRequest.Header.Set(k, v)
}
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
func (request *Request) addHeadersToRequest(baseRequest *retryablehttp.Request) { | |
for k, v := range request.Headers { | |
baseRequest.Header.Set(k, v) | |
} | |
} | |
func (request *Request) addHeadersToRequest(baseRequest *retryablehttp.Request) { | |
// List of headers that require special handling | |
sensitiveHeaders := map[string]bool{ | |
"Authorization": true, | |
"Cookie": true, | |
"Origin": true, | |
} | |
for k, v := range request.Headers { | |
// Basic validation | |
if k == "" || strings.Contains(k, "\n") || strings.Contains(v, "\n") { | |
continue | |
} | |
// Log modifications to sensitive headers | |
if sensitiveHeaders[k] { | |
gologger.Debug().Msgf("Modifying sensitive header: %s", k) | |
} | |
baseRequest.Header.Set(k, v) | |
} | |
} |
Proposed changes
Closes #5983
Checklist
Summary by CodeRabbit