Skip to content

fix: Prevent open redirect vulnerability in /learn endpoint#3

Merged
galanko merged 1 commit into
masterfrom
opensec/fix/open-redirect-validation
May 15, 2026
Merged

fix: Prevent open redirect vulnerability in /learn endpoint#3
galanko merged 1 commit into
masterfrom
opensec/fix/open-redirect-validation

Conversation

@galanko
Copy link
Copy Markdown

@galanko galanko commented May 14, 2026

Summary

Automated remediation for open redirect vulnerability (semgrep finding: express-open-redirect). The application was redirecting to URLs specified by user-supplied input without validation, allowing attackers to redirect users to malicious sites.

Changes

New Files

  1. app/utils/urlValidator.js - Core URL validation utility with validateRedirectUrl() function and safeRedirect() middleware for secure redirects

  2. config/redirectWhitelist.js - Configuration file for defining allowed external redirect domains

  3. test/urlValidatorTest.js - Comprehensive test suite with 40+ test cases

Modified Files

  1. app/routes/index.js - Replaced insecure redirect with validated safeRedirect() call

Security Impact

✅ Prevents open redirect attacks
✅ Allows internal redirects
✅ Whitelists external domains
✅ Blocks dangerous protocols
✅ Security logging for monitoring
✅ No breaking changes


Generated by OpenSec remediation agent

- Add URL validation utility with allow-list checking for redirects
- Implement safeRedirect middleware that validates all redirect destinations
- Add configuration file for whitelisted redirect domains
- Replace insecure res.redirect() with validated safeRedirect()
- Add comprehensive unit tests for URL validation
- Block protocol-relative URLs, non-whitelisted domains, and dangerous protocols
- Allow internal relative redirects and whitelisted external domains
- Include security logging for rejected redirect attempts
@galanko galanko marked this pull request as ready for review May 15, 2026 12:36
@galanko galanko merged commit 609ba56 into master May 15, 2026
@galanko galanko deleted the opensec/fix/open-redirect-validation branch May 15, 2026 12:36
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.

1 participant