Skip to content

fix: validate redirect URL in auth flow to prevent open redirect#975

Closed
LikiosSedo wants to merge 1 commit intoMODSetter:devfrom
LikiosSedo:fix/validate-redirect-url
Closed

fix: validate redirect URL in auth flow to prevent open redirect#975
LikiosSedo wants to merge 1 commit intoMODSetter:devfrom
LikiosSedo:fix/validate-redirect-url

Conversation

@LikiosSedo
Copy link
Contributor

@LikiosSedo LikiosSedo commented Mar 25, 2026

Summary

  • Add isValidRedirectPath() validation in auth-utils.ts to ensure redirect URLs are relative paths, preventing open redirect attacks
  • Validates path starts with /, has no protocol/authority, and doesn't use // prefix

Test plan

  • Verify normal login redirect flow still works
  • Verify malicious URLs like https://evil.com or //evil.com are rejected

High-level PR Summary

This PR adds validation to the authentication redirect flow to prevent open redirect vulnerabilities. A new isValidRedirectPath() function is introduced that validates redirect URLs are safe relative paths on the same origin, rejecting absolute URLs, protocol-relative URLs (like //evil.com), and other malicious redirect attempts. The validation is integrated into getAndClearRedirectPath() to ensure all redirects go through this security check.

⏱️ Estimated Review Time: 5-15 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_web/lib/auth-utils.ts

Need help? Join our Discord

Analyze latest changes

Reject absolute URLs, protocol-relative URLs, and scheme injections
in the stored redirect path. Only allow same-origin relative paths.

Closes MODSetter#949
@vercel
Copy link

vercel bot commented Mar 25, 2026

@LikiosSedo is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

@recurseml recurseml bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by RecurseML

🔍 Review performed on a474c46..38bad05

✨ No bugs found, your code is sparkling clean

✅ Files analyzed, no issues (1)

surfsense_web/lib/auth-utils.ts

@MODSetter
Copy link
Owner

@LikiosSedo Our auth is on the backend, which is on a separate URL/domain. This will block that. Let's not add this.

@MODSetter MODSetter closed this Mar 25, 2026
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.

2 participants