# VNX-482: Comparing instead of Assigning

Detects a statement that only compares, x == y; (or a Python test line cart.total == 0 with no assert), and a for loop whose initialiser compares (for (i == 0.

| Field | Value |
|---|---|
| Rule ID | `VNX-482` |
| Severity | Medium |
| SARIF level | `warning` |
| Kind | `sast` |
| Languages | C, C++, JavaScript / TypeScript, Python |
| CWE | [CWE-482](https://cwe.mitre.org/data/definitions/482.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 | `comparison-statement` `cwe-482` |
| Source | [`internal/sast/rules/vnx-482.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-482.rego) |

## Overview

VNX-482 maps to [CWE-482: Comparing instead of Assigning](https://cwe.mitre.org/data/definitions/482.html). `session.isAdmin === false;` was meant to revoke a privilege and does nothing; `cart.total == 0` in a Python test was meant to be an `assert` and checks nothing. The rule reports a line that is only `lvalue == expression` (or `===` in JavaScript/TypeScript) used as a statement, and `for (i == 0; ...)`.

Not reported: comparisons that are part of a larger statement (`assert`, `return`, `if`, an assignment, a call argument, a ternary, `a == b && f()`), continuation lines of a multi-line expression (the previous line ends with an operator, a comma or an open bracket, or the next line continues it), Python docstrings, a comparison directly under `with pytest.raises(...)` or `self.assertRaises(...)` (evaluated on purpose to prove `__eq__` raises), comparisons inside strings and comments, and Java and C#, where a statement that only compares does not compile.

## What gets flagged

```c
s->authenticated == 0;           /* FLAGGED: meant = */
for (i == 0; i < n; i++)         /* FLAGGED */
```

```javascript
session.isAdmin === false;       // FLAGGED
```

```python
def test_clear():
    cart.clear()
    cart.total == 0              # FLAGGED: missing assert
```

## What is not flagged

```python
assert cart.total == 0
ok = a == b
```

## Remediation

1. Use `=` when an assignment was meant.
2. In tests, write `assert` (or the framework's assertion) in front of the comparison.
3. Enable the compiler or linter warning for unused expression results (`-Wunused-value`, ESLint `no-unused-expressions`, Ruff/Pylint `B015`/`W0104`).

## References

- [CWE-482: Comparing instead of Assigning](https://cwe.mitre.org/data/definitions/482.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-482
// nosec vnx-482
```

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