Keep protocol-relative URLs intact in Snowboard's Url utility - #1551
wakqasahmed wants to merge 1 commit into
Conversation
…cms#1538) Url.to() and Url.asset() only treated a URL as absolute if it had an explicit scheme, so protocol-relative URLs such as //host/script.js had their leading slashes stripped and were resolved against the site URL. Make the scheme optional in the absolute URL check.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review. Walkthrough
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~8 minutes Fixed issue severity: <fixed_issue_severity>Medium</fixed_issue_severity> Merge Risk: ⚪ Minimal · up to Protocol-relative URLs are preserved in both URL methods, with corresponding tests. No actionable merge risk remains beyond normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change enables intended third-party asset URLs in AJAX responses. Fully qualified external URLs already worked, and no attacker-controlled asset source was established. The remaining risk depends on who can supply asset URLs and which origins browsers are permitted to load. Retained concerns
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Hardening Proposals
🚥 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 |
Url.to()andUrl.asset()only treated a URL as absolute if it had an explicit scheme, so something like//maps.googleapis.com/maps/api/jshad its leading slashes stripped and got resolved as<site>/maps.googleapis.com/maps/api/js. For assets injected over AJAX throughX_WINTER_ASSETS, that 404 makesAssetLoader.loadScript()reject and the handler never finishes.As suggested on the issue, this just makes the scheme optional in the absolute-URL regex, in both methods. Relative paths, including ones with a single leading slash, still resolve against the base/asset URL as before.
I added a Jest test at
modules/system/tests/js/cases/snowboard/utilities/Url.test.jsthat imports theUrlutility from source, so it doesn't depend on the compiled bundle. It covers relative, absolute and protocol-relative URLs for both methods. The protocol-relative case fails without the change, and the fullmodule-systemJS suite passes with it (48 tests). I've left the compiled Snowboard bundles alone, following how other recent Snowboard fixes were submitted. Happy to include a rebuild if you'd prefer.Fixes #1538
Summary by CodeRabbit