Repository navigation
fix: allow root cookie domain host redirects - #409
Conversation
WalkthroughRefactors IsRedirectSafe to short-circuit and return true when the redirect host equals the provided domain; otherwise it falls back to GetCookieDomain(redirectURL) and returns true only if that cookie domain equals the domain. Tests updated and a new multi-level domain test added. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller
participant IsRedirectSafe
participant Parser
participant CookieDomain
Caller->>IsRedirectSafe: IsRedirectSafe(redirectURL, domain)
IsRedirectSafe->>Parser: parse redirectURL -> host
Parser-->>IsRedirectSafe: host
alt host == domain
IsRedirectSafe-->>Caller: return true
else host != domain
IsRedirectSafe->>CookieDomain: GetCookieDomain(redirectURL)
CookieDomain-->>IsRedirectSafe: cookieDomain / error
alt cookieDomain == domain
IsRedirectSafe-->>Caller: return true
else
IsRedirectSafe-->>Caller: return false
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
internal/utils/app_utils.go(2 hunks)
🔇 Additional comments (1)
internal/utils/app_utils.go (1)
5-5: LGTM! Necessary import for maps.Copy usage.The
mapsimport is required for themaps.Copycalls on lines 156 and 176. This import was likely missing before, which would have caused compilation issues.
213d0eb to
55ba4e9
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
internal/utils/app_utils_test.go (1)
160-203: Consider adding test for deeper subdomain rejection.While the existing tests cover the primary scenarios, the past review comment suggested adding a test case for deeper subdomain rejection (e.g.,
foo.service1.example.com→example.com→false). This would help prevent regression and ensure the cookie domain computation correctly rejects redirects where the computed cookie domain doesn't match.Add this test case after line 197:
+ // Case with deeper subdomain (should be rejected) + redirectURL = "http://deep.sub.example.com/page" + result = utils.IsRedirectSafe(redirectURL, domain) + assert.Equal(t, false, result) +
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
internal/utils/app_utils.go(1 hunks)internal/utils/app_utils_test.go(1 hunks)
🔇 Additional comments (2)
internal/utils/app_utils_test.go (1)
164-167: LGTM! Test expectation correctly updated.The change from
falsetotruealigns with the new behavior where redirecting to the exact cookie domain host (e.g.,example.com→example.com) is now permitted. This correctly reflects the fix for issue #408.internal/utils/app_utils.go (1)
103-113: Excellent fix for the multi-level domain redirect issue!The early host equality check (lines 103-106) correctly addresses issue #408 by allowing redirects to the exact cookie domain host. The fallback to cookie domain computation (lines 108-113) maintains safety for subdomain redirects.
Logic verification:
- ✅ Root cookie domain redirect (
cluster.domain.com→cluster.domain.com): Line 104 returns true- ✅ Same-level subdomain (
service1.cluster.domain.com→cluster.domain.com): Line 113 comparison passes- ✅ Malicious domain: GetCookieDomain error causes rejection
55ba4e9 to
036ee13
Compare
|
@steveiliop56 since this is a change in behaviour for what appears to be some kind a security improvement introduced in v4, I've tried not to alter things too much. However, currently there is still an issue where if you have higher level domains, these will be rejected. E.g. |
Previously IsRedirectSafe rejected redirects to the exact cookie domain when AppURL had multiple subdomain levels, because it stripped the first label twice.
036ee13 to
abc9fc2
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #409 +/- ##
==========================================
+ Coverage 24.11% 24.22% +0.10%
==========================================
Files 35 35
Lines 2778 2778
==========================================
+ Hits 670 673 +3
+ Misses 2072 2070 -2
+ Partials 36 35 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thank you! |
Fixes #408
Previously IsRedirectSafe rejected redirects to the exact cookie domain when AppURL had multiple subdomain levels, because it stripped the first label twice.
Summary by CodeRabbit
Bug Fixes
Tests