# VNX-796: Only Filtering Special Elements Relative to a Marker

Path or command sanitising that strips special elements only at the start or end: strip('./'), lstrip('../'), _.trimStart(s, './'), re.sub(r'^(\.\./)+', '', p).

| Field | Value |
|---|---|
| Rule ID | `VNX-796` |
| Severity | Low |
| SARIF level | `note` |
| Kind | `sast` |
| Languages | Python, JavaScript / TypeScript |
| CWE | [CWE-796](https://cwe.mitre.org/data/definitions/796.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 | `only-end-special-element` `cwe-796` |
| Source | [`internal/sast/rules/vnx-796.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-796.rego) |

## Overview

VNX-796 maps to [CWE-796: Only Filtering Special Elements Relative to a Marker](https://cwe.mitre.org/data/definitions/796.html). It reports sanitising that removes special elements only at the beginning or end of a value:

- Python `str.strip`/`lstrip`/`rstrip` and lodash `_.trim`/`_.trimStart`/`_.trimEnd` whose character set mixes a dot with a path separator (`'./'`, `'../\\'`), or holds two or more shell metacharacters (`;`, `|`, `&`, `$`, a backtick), or one of them with a command (`exec`, `subprocess`, `os.system`...) within six lines
- Python `str.removeprefix`/`removesuffix` of a `..` sequence (`removeprefix('../')` removes one copy)
- Python `re.sub` and JavaScript `replace()` with an empty replacement whose pattern is anchored with `^` or `$` and removes dots with path separators (`^(\.\./)+`, `^[./\\]+`) or shell metacharacters (with the same two-or-command test)

Plain normalisation (`rstrip('/')`, `lstrip('.')`, `strip('"')`, `strip('<>')` on a Message-ID, `rstrip(';')` on an SQL statement, `strip('$')` on a price), stripping a file extension (`/\.[^/.]+$/`) and unanchored global replacements are not reported.

## Why this matters

`'a/../../etc/passwd'.lstrip('./')` is unchanged, and `re.sub(r'^(\.\./)+', '', 'x/../../etc')` removes nothing. The filter only acts at the edge of the value, so the same sequence one character in survives.

## What gets flagged

```python
name = name.lstrip("./")                  # FLAGGED
return re.sub(r'^(\.\./)+', '', p)        # FLAGGED
arg = arg.rstrip(";|&")                   # FLAGGED
```

```javascript
const clean = name.replace(/^(\.\.\/)+/, '');   // FLAGGED
```

## Remediation

1. Resolve the joined path (`os.path.realpath`, `path.resolve`) and check it is under the base directory.
2. Validate the whole value against an allow-list rather than trimming its ends.

## References

- [CWE-796: Only Filtering Special Elements Relative to a Marker](https://cwe.mitre.org/data/definitions/796.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-796
// nosec vnx-796
```

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