Skip to content

Fix for CWE-601: URL Redirection to Untrusted Site ('Open Redirect') - #57

Open
asadeddin wants to merge 1 commit into
masterfrom
corgea_fix_59c0e315
Open

Fix for CWE-601: URL Redirection to Untrusted Site ('Open Redirect')#57
asadeddin wants to merge 1 commit into
masterfrom
corgea_fix_59c0e315

Conversation

@asadeddin

Copy link
Copy Markdown

🐕 Corgea issued a PR to fix a vulnerability found in data/static/codefixes/redirectChallenge_3.ts.

It is CWE-601: URL Redirection to Untrusted Site ('Open Redirect') that has a severity of 🔴 High.

🪄 Fix explanation

The fix mitigates the open redirect vulnerability by parsing URLs and ensuring that only URLs with matching origins and paths from an allowlist are permitted, preventing redirection to untrusted sites.
- The code now uses "new URL(url)" to parse the input URL, ensuring it is a valid URL format.
- It compares the "origin" and "pathname" of the input URL with those of the allowlisted URLs using "parsedUrl.origin === allowedParsedUrl.origin".
- A "try-catch" block is added to handle any exceptions from invalid URL parsing, setting "allowed" to "false" if an error occurs.
- The use of "escapeHTML" is removed, as URL parsing inherently handles URL encoding and decoding.

💡 Important Instructions

Ensure that the allowlist contains fully qualified URLs with both origin and path to match against.

See the issue and fix in Corgea.

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