# VNX-1389: Incorrect Parsing of Numbers with Different Radices

Reports parsers that guess the radix from the text (parseInt without a radix on request data, int(x, 0), strconv.ParseInt(s, 0, n), Integer.decode, strtol(s.

| Field | Value |
|---|---|
| Rule ID | `VNX-1389` |
| Severity | Low |
| SARIF level | `note` |
| Kind | `sast` |
| Languages | JavaScript / TypeScript, Python, Go, Java, Kotlin, C, C++ |
| CWE | [CWE-1389](https://cwe.mitre.org/data/definitions/1389.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 | `radix-parsing` `input-validation` `cwe-1389` |
| Source | [`internal/sast/rules/vnx-1389.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-1389.rego) |

## Overview

VNX-1389 maps to [CWE-1389: Incorrect Parsing of Numbers with Different Radices](https://cwe.mitre.org/data/definitions/1389.html). Several parsing APIs infer the radix from a prefix: a leading `0` means octal, `0x` hexadecimal. When the text comes from outside the program, a value that passes a check in one radix means something else in another. The classic case is an IP allow-list bypassed with `0177.0.0.1`, which `inet_aton` reads as `127.0.0.1`.

## What gets flagged

```javascript
const page = parseInt(req.query.page);          // no radix, request data
const raw = req.params.port;
const port = parseInt(raw);                      // two-line form
```

```python
mode = int(request.args.get("mode"), 0)          # base inferred from prefix
```

```go
n, err := strconv.ParseUint(s, 0, 32)
```

```java
int limit = Integer.decode(request.getParameter("limit"));
```

```c
long port = strtol(port_text, &end, 0);
if (inet_aton(addr_text, &a) == 0) return 0;
int n; sscanf(buf, "%i", &n);                      // %i guesses the radix too
```

Not flagged: an explicit radix (`parseInt(x, 10)`, `int(x, 16)`, `strtol(s, NULL, 10)`), `parseInt` on values that are not request data (CSS widths, lengths), string-literal arguments, `Number()`, `Integer.parseInt`, `inet_pton`, and wrappers such as `malloc_strtoumax`.

## Remediation

1. Pass the radix the input is supposed to be in: `parseInt(value, 10)`, `int(value, 10)`, `strconv.ParseInt(s, 10, 64)`, `Integer.parseInt(s, 10)`, `strtol(s, &end, 10)`.
2. Parse IPv4 addresses with `inet_pton(AF_INET, ...)` (or `ipaddress.ip_address` / `net.ParseIP`), which accept dotted decimal only.
3. Validate the parsed value, not the text, and compare in one canonical form.

## References

- [CWE-1389: Incorrect Parsing of Numbers with Different Radices](https://cwe.mitre.org/data/definitions/1389.html)
- [MDN: parseInt radix](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)

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

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