fix: Prevent open redirect vulnerability in /learn endpoint#3
Merged
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
app/utils/urlValidator.js - Core URL validation utility with validateRedirectUrl() function and safeRedirect() middleware for secure redirects
config/redirectWhitelist.js - Configuration file for defining allowed external redirect domains
test/urlValidatorTest.js - Comprehensive test suite with 40+ test cases
Modified Files
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