Fix server fetches a URL the caller controls in Sails.js

An outbound HTTP request is made to a URL that came from the caller. The server can reach hosts the caller cannot - cloud metadata endpoints, internal admin services, databases bound to localhost - so this turns the server into a proxy into its own network. Validate the destination against an allowlist before fetching it.

high likely Sails.js CWE-918 / OWASP A10:2021

The vulnerable pattern in Sails.js

HIGH likely Server fetches a URL the caller controls A10:2021 api/controllers/AuthController.js:56:28 54 │ async importRemote(req, res) { 55 │ // ssrf: the server fetches whatever host the caller names. 56 │ const upstream = await fetch(req.body.sourceUrl) │ ~~~~~~~~~~~~~~~~~~~~~~~~~ destination chosen by the caller 57 │ return res.json(await upstream.json()) 58 │ },

This finding comes from the Sails.js fixture in the owlwarden test suite, in /auth. The destination of this request comes from the caller, so they choose which host the server connects to. That includes hosts they cannot reach themselves: the cloud metadata endpoint that hands out IAM credentials, internal services that skip authentication because they are 'not exposed', and anything bound to localhost.

The corrected handler

Validate in the action, not a helper, so every caller is covered.

const target = assertAllowedUrl(inputs.url)
const upstream = await fetch(target, { redirect: 'error' })

If you are not using Sails.js

Check the destination against an allowlist of hosts before fetching it. Blocklists do not work here: DNS rebinding, redirects, and IPv6-mapped addresses all defeat them.

Check your own repository

npx owlwarden scan
npx owlwarden explain ssrf

Runs on your machine. No account, no telemetry, no network unless you ask. In CI, SARIF uploads to code scanning and the exit code is the gate.

Other Sails.js checks

Rules with a tested Sails.js example.

ssrf for every framework / All rules / owlwarden