# VNX-807: Reliance on Untrusted Inputs in a Security Decision

Reports an authorization decision taken on a value the client sends and can set to anything.

| Field | Value |
|---|---|
| Rule ID | `VNX-807` |
| Severity | Medium |
| SARIF level | `warning` |
| Kind | `sast` |
| Languages | Java, JavaScript / TypeScript, Python |
| CWE | [CWE-807](https://cwe.mitre.org/data/definitions/807.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:M/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:M/DI:H/EX:M/EC:N/P:C` |
| Tags | `security-critical-input` `cwe-807` `authorization` |
| Source | [`internal/sast/rules/vnx-807.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-807.rego) |

## Overview

VNX-807 maps to [CWE-807: Reliance on Untrusted Inputs in a Security Decision](https://cwe.mitre.org/data/definitions/807.html). It reports code that decides who is an administrator, or who is authenticated, from a cookie, header or request parameter the client controls.

## What gets flagged

```javascript
// FLAGGED
if (req.query.admin === 'true') { return res.render('admin'); }
if (req.headers['x-user-role'] == 'admin') { ... }
const role = req.cookies.role;
if (role === 'admin') { ... }
```

```python
# FLAGGED
if request.headers.get("X-Authenticated") == "true":
    return HttpResponse("welcome admin")
cookie = request.COOKIES["cookie"]
if cookie.split("|")[0] == "admin":
    return HttpResponse("welcome admin")
```

```java
// FLAGGED
if ("true".equals(request.getParameter("isAdmin"))) { showAdmin(response); }
public String reports(@RequestHeader("X-User-Role") String role) {
    if ("ADMIN".equals(role)) { return "all"; }
```

Not flagged: `req.session.role === 'admin'`, `req.signedCookies.admin`, `request.user.is_staff`, `request.isUserInRole("admin")`, `if (theme == "dark")`.

Reported by [VNX-784](/sast/rules/vnx-784.md), not VNX-807: a cookie named for a privilege or login state that is compared or tested on the line that reads it, or assigned there to a variable that a condition uses within 15 lines (`if (req.cookies.isAdmin === 'true')`, `if request.COOKIES.get('admin') == "1":`). That is a security decision on a cookie, the case CWE-784 names, so it is reported once, there. Other cookies, headers and parameters stay with VNX-807, which also owns a cookie value compared with a privileged literal (`cookie.split("|")[0] == "admin"`), so [VNX-863](/sast/rules/vnx-863.md) does not report that line.

```javascript
// FLAGGED: destructured cookie, optional chaining, switch
const { role } = req.cookies;
if (role === 'admin') return next();
if (req.cookies?.isAdmin === 'true') return next();
switch (req.headers['x-user-role']) { case 'admin': /* ... */ }
```

```python
# FLAGGED: FastAPI header parameter decides access
def delete_user(user_id: int, x_role: str = Header(default="user")):
    if x_role != "admin":
        raise HTTPException(status_code=403)
```

Not flagged: `if (req.body.role === 'admin' && !req.user.isAdmin) return res.status(403)`, which checks the requested role against server-side identity.

## Remediation

1. Decide on state the server owns: the authenticated session, a verified token's claims, or the user record.
2. If a cookie must carry a role, sign it and verify the signature before reading it.
3. Do not trust identity headers unless a gateway you control sets them and strips client copies.

## References

- [CWE-807: Reliance on Untrusted Inputs in a Security Decision](https://cwe.mitre.org/data/definitions/807.html)
- [OWASP Authorization Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Authorization_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-807
// nosec vnx-807
```

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