-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next 13 #1305
base: main
Are you sure you want to change the base?
Next 13 #1305
Conversation
const axiosRes = await axios.get(url, {responseType: 'stream'}); | ||
|
||
if (axiosRes.status === 200) { | ||
const fetchRes = await fetch(url); |
Check failure
Code scanning / CodeQL
Server-side request forgery Critical
URL
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 8 days ago
To fix the problem, we need to ensure that the user input does not directly influence the URL in a way that could lead to SSRF. One effective way to do this is to use a whitelist of allowed IDs or to ensure that the constructed URL is safe. Since the IDs are already validated to be 32-character hexadecimal strings, we can focus on ensuring the base URL and query parameters are safe.
- Use a fixed base URL from an environment variable.
- Ensure the IDs are appended in a controlled manner.
- Validate the final URL before making the request.
-
Copy modified lines R22-R24 -
Copy modified line R26
@@ -21,8 +21,7 @@ | ||
try { | ||
const url = | ||
`${process.env.API_URL}/items/` + | ||
`${validIds.join(",")}` + | ||
`?api_key=${process.env.API_KEY}`; | ||
const baseUrl = new URL(`${process.env.API_URL}/items/`); | ||
baseUrl.searchParams.set('api_key', process.env.API_KEY); | ||
baseUrl.pathname += validIds.join(","); | ||
|
||
const fetchRes = await fetch(url); | ||
const fetchRes = await fetch(baseUrl.toString()); | ||
if (fetchRes.ok) { |
|
||
let data = {}; | ||
try { | ||
const res = await fetch(itemUrl); |
Check failure
Code scanning / CodeQL
Server-side request forgery Critical
URL
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 days ago
To fix the problem, we need to ensure that the itemId
parameter from context.query
is validated against a known set of valid item IDs or a specific pattern before constructing the itemUrl
. This will prevent attackers from manipulating the itemId
to create malicious URLs.
The best way to fix this is to implement a validation function that checks if the itemId
is in a valid format (e.g., a numeric ID or a specific pattern) and only then constructs the itemUrl
. If the itemId
is not valid, we should return a notFound
response.
-
Copy modified lines R83-R89 -
Copy modified line R94
@@ -82,2 +82,9 @@ | ||
} | ||
|
||
const itemId = query.itemId; | ||
const isValidItemId = /^[a-zA-Z0-9_-]+$/.test(itemId); // Example validation pattern | ||
if (!isValidItemId) { | ||
return notFound; | ||
} | ||
|
||
const isQA = false; | ||
@@ -86,3 +93,3 @@ | ||
const itemUrl = | ||
`${process.env.API_URL}/items/${query.itemId}` + | ||
`${process.env.API_URL}/items/${itemId}` + | ||
`?api_key=${process.env.API_KEY}`; |
|
||
if (query.q && !isBalanced(query.q)) { | ||
// User gave us something that will blow up, strip it out. | ||
query.q = query.q.replace(/['"\[\](){}]/, ""); |
Check failure
Code scanning / CodeQL
Incomplete string escaping or encoding High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 days ago
To fix the problem, we need to ensure that all occurrences of the specified characters are removed from the user input. This can be achieved by using a regular expression with the global flag (g
). Additionally, we should ensure that the backslash character itself is also escaped properly.
The best way to fix this is to replace the current replace
method call with a regular expression that matches all occurrences of the specified characters and removes them. This change should be made on line 107.
-
Copy modified line R107
@@ -106,3 +106,3 @@ | ||
// User gave us something that will blow up, strip it out. | ||
query.q = query.q.replace(/['"\[\](){}]/, ""); | ||
query.q = query.q.replace(/['"\[\](){}]/g, ""); | ||
} |
No description provided.