fix(history): prevent open redirect via backslash protocol-relative URLs - #8114
fix(history): prevent open redirect via backslash protocol-relative URLs#8114contactjawad wants to merge 1 commit into
Conversation
sanitizePath collapsed leading forward slashes ("//evil.com" -> "/evil.com")
but left backslash variants untouched. Per the WHATWG URL spec, browsers treat
backslashes as forward slashes in the authority, so "\\evil.com", "/\evil.com"
and "\/evil.com" are equivalent to "//evil.com" and were still resolved
cross-origin. Collapse any run of two or more leading slashes/backslashes to a
single slash so they stay same-origin.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthrough
ChangesSanitizePath hardening
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized security fix normalizes backslash-based protocol-relative paths while preserving existing behavior, with tests covering the affected variants; no actionable merge-blocking risk remains after normal checks and review. Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
Summary
sanitizePathguards against open redirects via protocol-relative URLs by collapsing leading//(e.g.//evil.com→/evil.com), but it only handled forward slashes. Per the WHATWG URL spec, browsers treat backslashes as forward slashes in the authority of a special-scheme URL, so the following all bypassed the guard and resolved cross-origin:\\evil.com/path/\evil.com/path\/evil.com/pathFix
Collapse any run of two or more leading slashes or backslashes to a single slash:
The existing
//behavior is unchanged; single leading slashes/backslashes (same-origin paths) are untouched.Test
Extended the
open redirect preventionblock inparseHref.test.tswith a case covering the three backslash variants, asserting the pathname collapses to/evil.com/pathand the resolvedURLstays same-origin. It fails onmain(the backslashes are left intact, so the resolved origin becomesevil.com) and passes with this change. A changeset is included.Summary by CodeRabbit