-
Notifications
You must be signed in to change notification settings - Fork 1k
fix: update Host header for favicon requests after redirects #2369
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
fix: update Host header for favicon requests after redirects #2369
Conversation
When FollowRedirects is enabled and the target redirects to a different host (e.g., hackerone.com -> www.hackerone.com), the favicon URL is correctly resolved to the final host, but the cloned request's Host header still contains the original host. This causes the server to return 404 because the Host header doesn't match the URL. This fix updates the Host header to match the resolved URL host before making the favicon request.
WalkthroughThe HandleFaviconHash function in runner.go now updates the Host header on cloned requests when the resolved URL's host differs from the current Host. This ensures the Host header matches the final redirect target during favicon HTTP requests. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
runner/runner.go (1)
2628-2629: Consider updating Host header in fallback path for consistency.The fallback path sets
clone.SetURL(rootResolvedURL)but doesn't updateclone.Host. While typically both URLs derive from the samebaseNetso hosts match, adding the same Host update here would be more defensive.♻️ Suggested improvement
clone.SetURL(rootResolvedURL) +if rootResolvedURL.Host != "" && rootResolvedURL.Host != clone.Host { + clone.Host = rootResolvedURL.Host +} if respFav2, err3 := hp.Do(clone, httpx.UnsafeOptions{}); err3 == nil && len(respFav2.Data) > 0 {
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
runner/runner.go
🔇 Additional comments (1)
runner/runner.go (1)
2614-2618: LGTM! Fix correctly updates Host header after redirects.The fix properly addresses the issue where favicon requests fail after redirects to different hosts. By updating
clone.Hostto matchresolvedURL.Host, the request now targets the correct server.
Mzack9999
left a comment
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.
lgtm!
% echo "https://hackerone.com" | go run . -favicon -follow-redirects -json | jq .favicon
...
"172802237"
|
@coderabbitai create an issue for this PR if it doesn't exist |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain@Mzack9999, I'll check if there's an existing issue for this PR and create one if needed. 🏁 Script executed: Length of output: 237 @Mzack9999, no existing issue was found for this PR. I'll create one now. 🏁 Script executed: Length of output: 53 @Mzack9999, I've confirmed that no existing issue was found for this PR. I've created issue #2373 to track the favicon extraction bug with follow-redirects: 🔗 #2373 The issue has been assigned to you and includes:
|
Summary
FollowRedirectsis enabledProblem
When using
-favicon -follow-redirects, the favicon hash is not extracted because:hackerone.com→www.hackerone.com), the favicon URL is correctly resolved to the final hostReproduction
Fix
Update the Host header to match the resolved URL host before making the favicon request.
Testing
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.