Skip to content

Conversation

@gregory-legit
Copy link

🔍 The problem

Server-side request forgery
See issue in Legit

🔒 Fix Details

The code is vulnerable to Server-Side Request Forgery (SSRF) because it constructs a URL using user input (req.query.url) and makes a server-side request using needle.get(). To mitigate this, validate the URL to ensure it starts with 'http://' or 'https://', preventing potentially harmful requests to internal services.

diff --git a/app/routes/research.js b/app/routes/research.js
index 3b2f1c4..d4e5f6a 100644
--- a/app/routes/research.js
+++ b/app/routes/research.js
@@ -11,6 +11,11 @@ this.displayResearch = (req, res) => {
 
         if (req.query.symbol) {
             const url = req.query.url+req.query.symbol; 
+
+            if (!/^https?:\/\//.test(req.query.url)) {
+                return res.status(400).send("Invalid URL");
+            }
+
             return needle.get(url, (error, newResponse) => {
                 if (!error && newResponse.statusCode == 200)
                     res.writeHead(200, {'Content-Type': 'text/html'});

@sonarqubecloud
Copy link

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.

2 participants