fix: enforce host boundary in withBase to prevent SSRF via prefix attack#568
fix: enforce host boundary in withBase to prevent SSRF via prefix attack#568
Conversation
withBase() uses startsWith() to check if the input URL already contains the base URL. However, startsWith() does not enforce host boundaries, allowing an attacker to bypass the base URL: // baseURL = 'http://api.internal' // input = 'http://api.internal.attacker.com/steal' // startsWith matches → input returned as-is → SSRF Add a boundary check after the startsWith match: the character following the base URL must be '/', '?', '#', or end-of-string. This prevents prefix attacks where the attacker appends a suffix to the hostname. Fixes unjs#564
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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
Fixes #564
withBase()usesstartsWith()to check if the input URL already contains the base URL. This allows SSRF via prefix attacks:Fix
After the
startsWithmatch, verify the next character is a valid URL boundary (/,?,#, or end-of-string). This prevents hostname suffix attacks.http://api.internal.attacker.com/stealhttp://api.internal/usershttp://api.internal?foo=bar/usersSummary by CodeRabbit