# VNX-647: Authorization decided on a non-canonical request path

Reports an access-control check that compares the raw request path or URL (getRequestURI or Kotlin requestURI, req.path/url/originalUrl.

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

## Overview

VNX-647 maps to [CWE-647: Use of Non-Canonical URL Paths for Authorization Decisions](https://cwe.mitre.org/data/definitions/647.html). It reports a `startsWith`/`equals`/`===`/`in (...)` comparison of the raw request path against a literal such as `"/admin"`, on the value itself or a variable assigned from it, when the same line or the next three take an access decision (401/403, `sendError`, `abort`, a login redirect, a role or session check).

## Why this matters

Servers accept many spellings of one path: `/ADMIN` on a case-insensitive router, `//admin`, `/admin;jsessionid=x` in servlet containers, `/%61dmin`, `/public/../admin`. A check on the raw string sees a different path from the one the router dispatches, so the protected resource is served without the check.

## What gets flagged

```java
if (request.getRequestURI().startsWith("/admin") && !isAdmin(request)) {
    response.sendError(HttpServletResponse.SC_FORBIDDEN);
```

```javascript
if (req.path.startsWith('/admin') && !req.user?.isAdmin) {
  return res.status(403).send('Forbidden');
```

```python
if request.path.startswith("/admin") and not session.get("is_admin"):
    abort(403)
```

Not flagged: `URI.create(request.getRequestURI()).normalize().getPath()`, `request.getServletPath()`, `router.get('/admin', requireAdmin, ...)`, and path checks with no access decision nearby (`/static` caching, `/health`).

## Remediation

1. Enforce access in the router or the framework's security layer (Spring Security matchers, route middleware, view decorators) rather than by string tests on the URL.
2. If a path test is unavoidable, decode and normalise the path first (resolve `.` and `..`, collapse slashes, strip path parameters) and compare case-consistently.
3. Deny by default and allow known paths, not the other way round.

## References

- [CWE-647: Use of Non-Canonical URL Paths for Authorization Decisions](https://cwe.mitre.org/data/definitions/647.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-647
// nosec vnx-647
```

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