Request data in a file path or URL
Request data in a file path or URL. Passes request input straight to a file path or outbound URL (sendFile(req.query).
This is how the comment reads inline, under the flagged line.
Why it matters
../ in a path reads files outside the folder; a user-chosen URL lets them make your server call internal services (SSRF).
What to do
Map the input to an allowed value (an id to a known path or host) instead of using it directly.
Examples
res.sendFile(req.query.file);
res.sendFile(FILES[req.query.id]);
What it catches
It reads a pattern on each line, aware of strings and comments. Languages: TypeScript and JavaScript, Python. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.
Flagged
res.sendFile(req.query.file);
await fetch(req.body.url);
Left alone
res.sendFile(FILES[id]);
Research
Request data passed into a file path or an outbound URL. `../` reads files outside the folder, and a chosen URL reaches internal services.
Turn it off or change it
In a config file for the CLI, or in the API's rules field:
{
"rules": {
"disable": [
"request-to-path"
],
"severity": {
"request-to-path": "low"
}
}
}