# VNX-394: Unexpected Status Code or Return Value

Python code uses an HTTP response body (requests, httpx, a session) without checking its status.

| Field | Value |
|---|---|
| Rule ID | `VNX-394` |
| Severity | Low |
| SARIF level | `note` |
| Kind | `sast` |
| Languages | Python |
| CWE | [CWE-394](https://cwe.mitre.org/data/definitions/394.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:L/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:L/DI:H/EX:L/EC:N/P:L` |
| Tags | `status-code` `cwe-394` |
| Source | [`internal/sast/rules/vnx-394.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-394.rego) |

## Overview

VNX-394 maps to [CWE-394: Unexpected Status Code or Return Value](https://cwe.mitre.org/data/definitions/394.html). It reports two concrete shapes in Python:

- The body of a response from `requests`, `httpx` or a requests session (`.get/.post/.put/.patch/.delete/.head/.request`) read with `.json()`, `.text` or `.content`, either chained on the call or from the variable it was assigned to within the next 12 lines, with no `raise_for_status()`, `status_code`, `.ok` or `.status` check and no test of the response in between.
- A slice indexed directly by `find()`/`rfind()` of the same string (`s[s.find(":") + 1:]`, `s[:s.find("-")]`), which returns the wrong text when the substring is absent (-1).

Not reported: a checked response, a module whose session installs a `raise_for_status` response hook, `s[s.rfind("/") + 1:]` (the after-last-separator idiom, which is correct when rfind returns -1), a cache or dict `.get()`, `soup.find()`, a `find()` result tested before use or guarded by an `in` test just above, test files, comments and docstrings.

## Why this matters

An HTTP client returns 4xx and 5xx responses as ordinary values. Code that parses them as success processes an error page as data, crashes with a confusing decode error, or stores an error message as if it were the record.

## What gets flagged

```python
r = requests.get(url, headers=headers)
return [repo["name"] for repo in r.json()]                 # FLAGGED

return requests.post(url, json=payload).json()["embedding"]  # FLAGGED

return line[line.find(":") + 1:].strip()                   # FLAGGED
```

## Remediation

1. Call `response.raise_for_status()` (or check `response.ok`/`status_code`) before reading the body.
2. Check `find()` for -1, or use `str.partition()` or `str.index()`, which make the missing case explicit.

## References

- [CWE-394: Unexpected Status Code or Return Value](https://cwe.mitre.org/data/definitions/394.html)
- [OWASP Top 10](https://owasp.org/www-project-top-ten/)

## 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-394
// nosec vnx-394
```

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