Repository navigation
adding protocols redirect - #7296
Conversation
Neo - PR Security ReviewNo security issues found Highlights
Hardening Notes
Comment |
WalkthroughThis change implements a new Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Request Handler
participant Redirect Check
participant FollowSameSchemeRedirect
participant Target Server
User->>Request Handler: Execute request with ProtocolRedirects=true
Request Handler->>Request Handler: Set RedirectFlow to FollowSameSchemeRedirect
Request Handler->>Target Server: Send initial HTTP request
Target Server-->>Request Handler: 3xx redirect response
Request Handler->>Redirect Check: Check if redirect allowed
Redirect Check->>FollowSameSchemeRedirect: Validate scheme consistency
FollowSameSchemeRedirect->>FollowSameSchemeRedirect: Compare URL.Scheme (current vs last)
alt Scheme matches (same protocol)
FollowSameSchemeRedirect->>Redirect Check: Check max redirects
Redirect Check-->>Request Handler: Redirect allowed
Request Handler->>Target Server: Follow redirect
else Scheme differs (protocol changed)
FollowSameSchemeRedirect-->>Redirect Check: http.ErrUseLastResponse
Redirect Check-->>Request Handler: Redirect blocked
Request Handler-->>User: Return last response
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 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 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/protocols/http/http.go`:
- Around line 345-347: The current logic sets
connectionConfiguration.RedirectFlow to FollowSameSchemeRedirect when
request.ProtocolRedirects is true, which unconditionally overrides a prior
FollowSameHostRedirect set when request.HostRedirects is true; update the
handling in the RedirectFlow selection so both restrictions are preserved:
either add and use a new enum/value like FollowSameHostAndSchemeRedirect and set
RedirectFlow to that when both request.HostRedirects and
request.ProtocolRedirects are true, or change the branching to an else-if chain
that prevents ProtocolRedirects from overwriting an already-set
FollowSameHostRedirect. Ensure you update any switch/assignment logic that
references RedirectFlow, and use the symbols ProtocolRedirects, HostRedirects,
RedirectFlow, FollowSameSchemeRedirect and FollowSameHostRedirect to locate and
modify the code.
In `@pkg/protocols/http/httpclientpool/clientpool.go`:
- Around line 402-407: The FollowSameSchemeRedirect branch currently compares
req.URL.Scheme against via[len(via)-1].URL.Scheme which is inconsistent with
FollowSameHostRedirect (which uses via[0]) and can allow scheme changes
mid-chain; change the comparison to use the original request's scheme
via[0].URL.Scheme and then call checkMaxRedirects as before (identify the code
in the FollowSameSchemeRedirect case that references via and checkMaxRedirects
and replace len(via)-1 with 0).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4b999dee-d8ec-4bfe-a7fb-fc45f3a989a0
📒 Files selected for processing (7)
pkg/protocols/http/cluster.gopkg/protocols/http/cluster_test.gopkg/protocols/http/http.gopkg/protocols/http/httpclientpool/clientpool.gopkg/protocols/http/httpclientpool/clientpool_test.gopkg/protocols/http/validate.gopkg/protocols/http/validate_test.go
| if request.ProtocolRedirects { | ||
| connectionConfiguration.RedirectFlow = httpclientpool.FollowSameSchemeRedirect | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check if there's any existing combined redirect mode or if this is the intended design
rg -n "FollowSame" pkg/protocols/http/httpclientpool/Repository: projectdiscovery/nuclei
Length of output: 1647
🏁 Script executed:
# Check the redirect logic implementations in clientpool.go
head -n 430 pkg/protocols/http/httpclientpool/clientpool.go | tail -n 70Repository: projectdiscovery/nuclei
Length of output: 2018
🏁 Script executed:
# Check the validation logic in http.go to understand allowed combinations
rg -n "ProtocolRedirects" pkg/protocols/http/ -A 3 -B 1Repository: projectdiscovery/nuclei
Length of output: 4262
🏁 Script executed:
# Check lines around 345 in http.go to see the full Compile logic for redirects
sed -n '310,360p' pkg/protocols/http/http.goRepository: projectdiscovery/nuclei
Length of output: 1776
🏁 Script executed:
rg -n "HostRedirects.*ProtocolRedirects|ProtocolRedirects.*HostRedirects" pkg/protocols/http/ -B 2 -A 5Repository: projectdiscovery/nuclei
Length of output: 1113
🏁 Script executed:
# Also check if there are any integration tests or behavioral tests for redirect combinations
find pkg/protocols/http -name "*test.go" -exec grep -l "HostRedirects\|ProtocolRedirects" {} \;Repository: projectdiscovery/nuclei
Length of output: 137
🏁 Script executed:
# Look for any tests or documentation about expected redirect behavior with both flags
rg -n "HostRedirects" pkg/protocols/http/http.go -B 5 -A 5Repository: projectdiscovery/nuclei
Length of output: 1696
🏁 Script executed:
# Check the description of HostRedirects to understand intent
sed -n '175,210p' pkg/protocols/http/http.goRepository: projectdiscovery/nuclei
Length of output: 3093
ProtocolRedirects unconditionally overrides HostRedirects, losing same-host restriction.
When both host-redirects: true and protocol-redirects: true are set, the current implementation at lines 345–346 unconditionally sets RedirectFlow = FollowSameSchemeRedirect, which only checks the scheme. This overwrites the previous FollowSameHostRedirect assignment at line 343, causing the host restriction to be lost.
The code validates this combination as valid (validate.go line 14), but there is no combined redirect mode available to enforce both same-host and same-scheme restrictions simultaneously. Either implement a new combined redirect mode (e.g., FollowSameHostAndSchemeRedirect) or use an else-if chain to prevent unintended overrides.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@pkg/protocols/http/http.go` around lines 345 - 347, The current logic sets
connectionConfiguration.RedirectFlow to FollowSameSchemeRedirect when
request.ProtocolRedirects is true, which unconditionally overrides a prior
FollowSameHostRedirect set when request.HostRedirects is true; update the
handling in the RedirectFlow selection so both restrictions are preserved:
either add and use a new enum/value like FollowSameHostAndSchemeRedirect and set
RedirectFlow to that when both request.HostRedirects and
request.ProtocolRedirects are true, or change the branching to an else-if chain
that prevents ProtocolRedirects from overwriting an already-set
FollowSameHostRedirect. Ensure you update any switch/assignment logic that
references RedirectFlow, and use the symbols ProtocolRedirects, HostRedirects,
RedirectFlow, FollowSameSchemeRedirect and FollowSameHostRedirect to locate and
modify the code.
| case FollowSameSchemeRedirect: | ||
| previousScheme := via[len(via)-1].URL.Scheme | ||
| if req.URL.Scheme != previousScheme { | ||
| return http.ErrUseLastResponse | ||
| } | ||
| return checkMaxRedirects(req, via, maxRedirects) |
There was a problem hiding this comment.
Inconsistent base for scheme comparison - consider using via[0] instead of via[len(via)-1].
The FollowSameSchemeRedirect case compares the scheme against the last request in the chain (via[len(via)-1]), whereas FollowSameHostRedirect (lines 391-394) compares the host against the original request (via[0]).
This inconsistency could lead to unexpected behavior. If the goal is to restrict redirects to the original protocol used to initiate the request (per issue #5887), the comparison should use via[0].URL.Scheme:
🐛 Proposed fix to use original request scheme
case FollowSameSchemeRedirect:
- previousScheme := via[len(via)-1].URL.Scheme
+ originalScheme := via[0].URL.Scheme
- if req.URL.Scheme != previousScheme {
+ if req.URL.Scheme != originalScheme {
return http.ErrUseLastResponse
}
return checkMaxRedirects(req, via, maxRedirects)📝 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.
| case FollowSameSchemeRedirect: | |
| previousScheme := via[len(via)-1].URL.Scheme | |
| if req.URL.Scheme != previousScheme { | |
| return http.ErrUseLastResponse | |
| } | |
| return checkMaxRedirects(req, via, maxRedirects) | |
| case FollowSameSchemeRedirect: | |
| originalScheme := via[0].URL.Scheme | |
| if req.URL.Scheme != originalScheme { | |
| return http.ErrUseLastResponse | |
| } | |
| return checkMaxRedirects(req, via, maxRedirects) |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@pkg/protocols/http/httpclientpool/clientpool.go` around lines 402 - 407, The
FollowSameSchemeRedirect branch currently compares req.URL.Scheme against
via[len(via)-1].URL.Scheme which is inconsistent with FollowSameHostRedirect
(which uses via[0]) and can allow scheme changes mid-chain; change the
comparison to use the original request's scheme via[0].URL.Scheme and then call
checkMaxRedirects as before (identify the code in the FollowSameSchemeRedirect
case that references via and checkMaxRedirects and replace len(via)-1 with 0).
nuclei 3.9.0 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## What's Changed ### 🎉 New Features * Added support for protocol redirects by @Mzack9999 in projectdiscovery/nuclei#7296 * Added impacket integration by @Mzack9999 in projectdiscovery/nuclei#7356 * Added wmi, tsch, scmr, and dcom helper modules for JS by @dwisiswant0 in projectdiscovery/nuclei#7388 * Added mirroring of -config, -report-config, and -dashboard flags for SDK callers by @ShubhamRasal in projectdiscovery/nuclei#7393 ### 🐞 Bug Fixes * Fixed DNS variables resolving issue by @Mzack9999 in projectdiscovery/nuclei#7379 * Fixed expressions to prefer exact placeholders over expressions by @dwisiswant0 in projectdiscovery/nuclei#7397 * Fixed an issue in JS where runtimes that outlive the interrupt grace period are not abandoned, by @Mzack9999 in projectdiscovery/nuclei#7378 * Fixed an issue in reporting/jira where status-not was not matched against the transition target status name by @knakul853 in projectdiscovery/nuclei#7361 * Fixed runner to write unsigned-templates warning (WRN) to stderr by @ChrisJr404 in projectdiscovery/nuclei#7371 * Fixed `InternalEvent` access serialization in interactsh by @dwisiswant0 in projectdiscovery/nuclei#7322 * Fixed workflow to ensure context is properly propagated to child and race steps by @dwisiswant0 in projectdiscovery/nuclei#7383 * Fixed reporting/gitlab by bumping client-go to v1.9.1 and widening IDs to int64 by @ShubhamRasal in projectdiscovery/nuclei#7398 * Fixed memogen to skip context correctly and auto-push scope to upstream by @Mzack9999 in projectdiscovery/nuclei#7419 * Fixed a slice-bounds panic in telnetmini's ParseNTLMResponse when handling truncated NTLM challenges by @tejgokani in projectdiscovery/nuclei#7425 * Fixed SMBv1 probing in JS to occur after SMB2 negotiation by @dwisiswant0 in projectdiscovery/nuclei#7430 * Fixed templates to reject unknown fields when loading JSON templates by @tejgokani in projectdiscovery/nuclei#7453 * Fixed persistence of QueryAuthStrategy parameters in ApplyAuthStrategy by @akhilesharora in projectdiscovery/nuclei#7410 * Fixed loader to warn when templates are excluded by `.nuclei-ignore` tags by @dogancanbakir in projectdiscovery/nuclei#7452 ### Other Changes * Splitted exact matches and pattern handling in catalog for improved performance by @mikhail5555 in projectdiscovery/nuclei#7340 * Updated README_PT-BR.md to reflect current project description and features by @gugacyber in projectdiscovery/nuclei#7405 * Fixed broken cloud scanning link by @dogancanbakir in projectdiscovery/nuclei#7413 * Bumped pdsec modules + govaluate/aurora migration by @dogancanbakir in projectdiscovery/nuclei#7414 * Dropped vulnerable docker/docker dependency by @dogancanbakir in projectdiscovery/nuclei#7447 * Used path-aware filesystem containment checks by @dwisiswant0 in projectdiscovery/nuclei#7420 * Centralized runtime session handling by @dwisiswant0 in projectdiscovery/nuclei#7449 ## New Contributors * @ChrisJr404 made their first contribution in projectdiscovery/nuclei#7371 * @gugacyber made their first contribution in projectdiscovery/nuclei#7405 * @akhilesharora made their first contribution in projectdiscovery/nuclei#7410 * @tejgokani made their first contribution in projectdiscovery/nuclei#7425 **Full Changelog**: https://github.com/projectdiscovery/nuclei/compare/v3.8.0...v3.9.0</pre> <p>View the full release notes at <a href="https://github.com/projectdiscovery/nuclei/releases/tag/v3.9.0">https://github.com/projectdiscovery/nuclei/releases/tag/v3.9.0</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!11229
Proposed changes
Close #5887
Checklist
Summary by CodeRabbit
New Features
protocol-redirectsoption for protocol-level redirect control in HTTP requests, requiring pairing with existing redirect options.Tests