Skip to content

[LEGIT] Fix - HTTP request redirections should not be open to forging attacks#97

Open
eli-tamarkin-legit wants to merge 1 commit into
masterfrom
legit-security-be3c22
Open

[LEGIT] Fix - HTTP request redirections should not be open to forging attacks#97
eli-tamarkin-legit wants to merge 1 commit into
masterfrom
legit-security-be3c22

Conversation

@eli-tamarkin-legit
Copy link
Copy Markdown

🔍 The problem

Change this code to not perform redirects based on user-controlled data.
See issue in Legit

🔒 Fix Details

The vulnerability is due to an open redirect on line 72 where the redirect URL is taken directly from user-controlled query parameters without validation. To fix this, we validate the redirect URL against a whitelist of allowed paths to prevent open redirect attacks. If the URL is not in the whitelist, we redirect to a safe default page (e.g., '/dashboard'). This approach avoids introducing new dependencies and ensures only safe redirects occur.

--- a/app/routes/index.js
+++ b/app/routes/index.js
@@ -70,6 +70,13 @@
     app.get("/learn", isLoggedIn, (req, res) => {
         // Insecure way to handle redirects by taking redirect url from query string
         return res.redirect(req.query.url);
+        const allowedRedirects = ['/dashboard', '/profile', '/benefits', '/contributions'];
+        const redirectUrl = req.query.url;
+        if (allowedRedirects.includes(redirectUrl)) {
+            return res.redirect(redirectUrl);
+        } else {
+            return res.redirect('/dashboard');
+        }
     });
 
     // Handle redirect for learning resources link

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant