CWE-1389 Base Incomplete

Incorrect Parsing of Numbers with Different Radices

This vulnerability occurs when software processes numeric input expecting standard decimal numbers (base 10), but fails to handle inputs formatted in other bases like octal or hexadecimal. This…

Definition

What is CWE-1389?

This vulnerability occurs when software processes numeric input expecting standard decimal numbers (base 10), but fails to handle inputs formatted in other bases like octal or hexadecimal. This mismatch leads to the system interpreting the same digits as a completely different numeric value.
The core issue often arises from functions that automatically interpret numeric prefixes. A leading '0' can trigger octal parsing, while '0x' indicates hexadecimal. For instance, the IP address '0127.0.0.1' is read as octal, becoming equivalent to 87.0.0.1 in decimal—a stark and dangerous difference from the intended 127.0.0.1 (localhost). Common C functions like `inet_addr()` exhibit this behavior, but the problem can appear in any parsing logic that doesn't explicitly define or validate the input's radix. In practice, this parsing flaw can have severe security consequences. An attacker can exploit it to bypass security controls, such as network allow/deny lists or SSRF (Server-Side Request Forgery) filters, by supplying an IP address or identifier that looks correct to a developer but resolves to a different, permitted address. It can also corrupt data flows when identifiers that resemble numbers with leading zeros are processed incorrectly, leading to logical errors and unexpected system behavior.
Real-world impact

Real-world CVEs caused by CWE-1389

  • Chain: Use of zero-prepended IP addresses in Perl-based IP validation module can lead to an access control bypass.

  • Chain: Use of zero-prepended IP addresses in a product that manages IP blocks can lead to an SSRF.

  • Chain: Use of zero-prepended IP addresses in a Python standard library package can lead to an SSRF.

  • Chain: Use of zero-prepended IP addresses in the net Golang library can lead to an access control bypass.

  • Chain: Use of zero-prepended IP addresses in Perl netmask module allows bypass of IP-based access control.

  • Chain: incorrect validation of intended decimal-based IP address format (CWE-1286) enables parsing of octal or hexadecimal formats (CWE-1389), allowing bypass of an SSRF protection mechanism (CWE-918).

  • Mishandling of hex-valued usernames leads to unexpected decimal conversion and privilege escalation in the systemd Linux suite.

How attackers exploit it

Step-by-step attacker path

  1. 1

    The below demonstrative example uses an IP validator that splits up an IP address by octet, tests to ensure each octet can be casted into an integer, and then returns the original IP address if no exceptions are raised. This validated IP address is then tested using the "ping" command.

  2. 2

    If run_ping() were to be called with one or more zero-prepended octets, validate_ip() will succeed as zero-prepended numerical strings can be interpreted as decimal by a cast ("012" would cast to 12). However, as the original IP with the prepended zeroes is returned rather than the casted IP, it will be used in the call to the ping command. Ping DOES check and support octal-based IP octets, so the IP reached via ping may be different than the IP assumed by the validator. For example, ping would considered "0127.0.0.1" the same as "87.0.0.1".

  3. 3

    This code uses a regular expression to validate an IP string prior to using it in a call to the "ping" command.

  4. 4

    Since the regular expression does not have anchors (CWE-777), i.e. is unbounded without ^ or $ characters, then prepending a 0 or 0x to the beginning of the IP address will still result in a matched regex pattern. Since the ping command supports octal and hex prepended IP addresses, it will use the unexpectedly valid IP address (CWE-1389). For example, "0x63.63.63.63" would be considered equivalent to "99.63.63.63". As a result, the attacker could potentially ping systems that the attacker cannot reach directly.

  5. 5

    Consider the following scenario, inspired by CWE team member Kelly Todd. Kelly wants to set up monitoring systems for his two cats, who pose very different threats. One cat, Night, tweets embarrassing or critical comments about his owner in ways that could cause reputational damage, so Night's blog needs to be monitored regularly. The other cat, Taki, likes to distract Kelly and his coworkers during business meetings with cute meows, so Kelly monitors Taki's location using a different web site. Suppose /etc/hosts provides the site info as follows:

Vulnerable code example

Vulnerable Python

The below demonstrative example uses an IP validator that splits up an IP address by octet, tests to ensure each octet can be casted into an integer, and then returns the original IP address if no exceptions are raised. This validated IP address is then tested using the "ping" command.

Vulnerable Python
import subprocess
   def validate_ip(ip: str):
  	 split_ip = ip.split('.')
  	 if len(split_ip) > 4 or len(split_ip) == 0:
  		 raise ValueError("Invalid IP length")
  	 for octet in split_ip:
  		 try:
  			 int(octet, 10)
  		 except ValueError as e:
  			 raise ValueError(f"Cannot convert IP octet to int - {e}")
```
# Returns original IP after ensuring no exceptions are raised* 
  	 return ip
  	
   def run_ping(ip: str):
  
  ```
  	 validated = validate_ip(ip)
```
# The ping command treats zero-prepended IP addresses as octal* 
  	 result = subprocess.call(["ping", validated])
  	 print(result)
Secure code example

Secure pseudo

Secure pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
  const safe = validateAndEscape(input);
  return executeWithGuards(safe);
}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Prevention checklist

How to prevent CWE-1389

  • Implementation If only decimal-based values are expected in the application, conditional checks should be created in a way that prevent octal or hexadecimal strings from being checked. This can be achieved by converting any numerical string to an explicit base-10 integer prior to the conditional check, to prevent octal or hex values from ever being checked against the condition.
  • Implementation If various numerical bases do need to be supported, check for leading values indicating the non-decimal base you wish to support (such as 0x for hex) and convert the numeric strings to integers of the respective base. Reject any other alternative-base string that is not intentionally supported by the application.
  • Implementation If regular expressions are used to validate IP addresses, ensure that they are bounded using ^ and $ to prevent base-prepended IP addresses from being matched.
Detection signals

How to detect CWE-1389

SAST High

Run static analysis (SAST) on the codebase looking for the unsafe pattern in the data flow.

DAST Moderate

Run dynamic application security testing against the live endpoint.

Runtime Moderate

Watch runtime logs for unusual exception traces, malformed input, or authorization bypass attempts.

Code review Moderate

Code review: flag any new code that handles input from this surface without using the validated framework helpers.

Plexicus auto-fix

Plexicus auto-detects CWE-1389 and opens a fix PR in under 60 seconds.

Codex Remedium scans every commit, identifies this exact weakness, and ships a reviewer-ready pull request with the patch. No tickets. No hand-offs.

Frequently asked questions

Frequently asked questions

What is CWE-1389?

This vulnerability occurs when software processes numeric input expecting standard decimal numbers (base 10), but fails to handle inputs formatted in other bases like octal or hexadecimal. This mismatch leads to the system interpreting the same digits as a completely different numeric value.

How serious is CWE-1389?

MITRE has not published a likelihood-of-exploit rating for this weakness. Treat it as medium-impact until your threat model proves otherwise.

What languages or platforms are affected by CWE-1389?

MITRE lists the following affected platforms: Not Technology-Specific.

How can I prevent CWE-1389?

If only decimal-based values are expected in the application, conditional checks should be created in a way that prevent octal or hexadecimal strings from being checked. This can be achieved by converting any numerical string to an explicit base-10 integer prior to the conditional check, to prevent octal or hex values from ever being checked against the condition. If various numerical bases do need to be supported, check for leading values indicating the non-decimal base you wish to support…

How does Plexicus detect and fix CWE-1389?

Plexicus's SAST engine matches the data-flow signature for CWE-1389 on every commit. When a match is found, our Codex Remedium agent opens a fix PR with the corrected code, tests, and a one-line summary for the reviewer.

Where can I learn more about CWE-1389?

MITRE publishes the canonical definition at https://cwe.mitre.org/data/definitions/1389.html. You can also reference OWASP and NIST documentation for adjacent guidance.

Ready when you are

Don't Let Security
Weigh You Down.

Stop choosing between AI velocity and security debt. Plexicus is the only platform that runs Vibe Coding Security and ASPM in parallel — one workflow, every codebase.