Skip to content

feat: add protocol validation to withBase to prevent SSRF#565

Open
stark-afk wants to merge 1 commit intounjs:mainfrom
stark-afk:fix/ssrf-baseurl-validation
Open

feat: add protocol validation to withBase to prevent SSRF#565
stark-afk wants to merge 1 commit intounjs:mainfrom
stark-afk:fix/ssrf-baseurl-validation

Conversation

@stark-afk
Copy link
Copy Markdown

@stark-afk stark-afk commented Apr 5, 2026

Description

This PR adds a security guardrail to the withBase utility. It ensures that if a baseURL is provided, it must use an explicit http:// or https:// protocol.

This prevents potential Server-Side Request Forgery (SSRF) or protocol injection attacks in cases where the baseURL might be derived from untrusted configuration or user input.

Key Changes

  • Validates that baseURL starts with http:// or https://.
  • Throws a descriptive error if an invalid protocol (like file://) or no protocol is used.

Related Issues

Resolves #564

Checklist

  • I have read the contribution guidelines.
  • I have added tests to cover these changes.
  • All tests passed locally.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed URL handling to properly validate base prefix boundaries. The system now correctly checks that matched base prefixes are followed by path boundaries (/, ?, #) or string end, preventing incorrect interpretation of partial-prefix matches.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c7eae71-c956-4256-bf7e-721e6fac1fd1

📥 Commits

Reviewing files that changed from the base of the PR and between dfbe3ca and 02fc1b6.

📒 Files selected for processing (1)
  • src/utils.url.ts

📝 Walkthrough

Walkthrough

Updated the withBase() function in URL utilities to add boundary validation. When input starts with the normalized base, it now checks that the following character is a boundary character (/, ?, #) or end-of-string before returning input as-is. Otherwise, it joins the base with input.

Changes

Cohort / File(s) Summary
Boundary Validation in URL Base Matching
src/utils.url.ts
Added boundary character validation in withBase() to prevent partial-prefix matches from bypassing base URL constraints. The function now verifies that characters immediately following the matched base are valid URL separators or end-of-string.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A URL rabbit caught a sneaky foe,
Partial prefixes with malicious flow—
Now boundaries guard the path we take,
No more shortcuts for a hacker's sake! 🛡️✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning Title mentions protocol validation but the PR actually implements boundary checking in withBase, which is the core security fix for SSRF prevention. Update title to reflect the actual change: 'fix: add boundary checking to withBase to prevent SSRF' or similar, as the main fix is enforcing URL separator boundaries.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #564: boundary checking after the base URL with proper character validation (/,?,# or end-of-string) and withoutTrailingSlash normalization.
Out of Scope Changes check ✅ Passed All changes in src/utils.url.ts are directly related to implementing the boundary checking security fix specified in issue #564; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSRF via Unconstrained baseURL + Open Redirect

1 participant