# VNX-918: Server-Side Request Forgery (SSRF)

Reports an outbound HTTP request in Python whose URL or host comes from the incoming request, inline.

| Field | Value |
|---|---|
| Rule ID | `VNX-918` |
| Severity | High |
| SARIF level | `error` |
| Kind | `sast` |
| Languages | Python |
| CWE | [CWE-918](https://cwe.mitre.org/data/definitions/918.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:H/AP:A/AL:A/IC:N/FC:LT/RP:N/RL:A/AV:I/AS:N/IN:A/SC:A/BI:H/DI:H/EX:H/EC:N/P:H` |
| Tags | `ssrf` `cwe-918` |
| Source | [`internal/sast/rules/vnx-918.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-918.rego) |

## Overview

The destination of a server-side HTTP request comes from the incoming request. Python: the URL argument of `requests.*`, `httpx.*` (including `request(method, url)` and `stream(method, url)`), methods on a `requests.Session()`, `httpx.Client()`/`AsyncClient()` or `aiohttp.ClientSession()` object in the same file, `urllib.request.urlopen` and `urllib.request.Request`. The URL must be request data inline, interpolated into the host, concatenated after a bare scheme, or carried by a variable assigned from it in the 20 lines above (one further assignment is followed).

## Why this matters

The server can reach places the client cannot: internal services, admin ports and the cloud metadata endpoint that hands out credentials.

## What gets flagged

```python
r = requests.post(request.POST.get("callback"), json={"done": True})
httpx.post(f"http://{host}/hook", json={"ok": True})
upstream = requests.request("HEAD", target, timeout=10)
```

Not flagged: a URL whose host is fixed by a literal prefix or by an UPPER_CASE, `settings.*` or `config.*` base, request data passed only as query parameters, body or headers, a destination checked against an allow-list in the lines above, URLs from the environment or configuration, comments and strings.

Reported by other rules, so one request is one finding:

- JavaScript and TypeScript requests are reported by [VNX-NODE-009](/sast/rules/vnx-node-009.md), the Node.js form of this rule.
- A request whose response is then returned to the caller (`return r.content`, `HttpResponse(resp.read())`) is reported by [VNX-441](/sast/rules/vnx-441.md): the service is an open proxy, the form of SSRF in which the attacker also reads what the server fetched.

## Remediation

Fix the host on the server and take only a path or an identifier from the client. Where a client must name a destination, check its parsed host against an allow-list and refuse private, loopback and link-local addresses after resolution.

## References

- [CWE-918: Server-Side Request Forgery (SSRF)](https://cwe.mitre.org/data/definitions/918.html)
- [OWASP SSRF Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html)

## Suppressing this rule

Put a `nosec` comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file's language (`#`, `//`, `--` or `;`):

```text
# nosec vnx-918
// nosec vnx-918
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-918 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
