Ejecuta análisis estático (SAST) sobre el código buscando el patrón inseguro en el flujo de datos.
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…
What is CWE-1389?
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.
Ruta del atacante paso a paso
- 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
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
This code uses a regular expression to validate an IP string prior to using it in a call to the "ping" command.
- 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
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 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.
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 pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
const safe = validateAndEscape(input);
return executeWithGuards(safe);
} 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.
How to detect CWE-1389
Ejecuta pruebas dinámicas de seguridad de aplicaciones (DAST) contra el endpoint en vivo.
Vigila los logs en tiempo de ejecución para detectar trazas de excepción inusuales, entradas malformadas o intentos de bypass de autorización.
Revisión de código: marca cualquier código nuevo que maneje entrada desde esta superficie sin usar los helpers validados del framework.
Plexicus detecta automáticamente CWE-1389 y abre un PR de corrección en menos de 60 segundos.
Codex Remedium escanea cada commit, identifica esta debilidad concreta y entrega un pull request listo para revisión con el parche. Sin tickets. Sin traspasos.
Frequently asked questions
¿Qué es 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.
¿Qué gravedad tiene CWE-1389?
MITRE no ha publicado una calificación de probabilidad de explotación para esta debilidad. Trátala como de impacto medio hasta que tu modelo de amenazas demuestre lo contrario.
¿Qué lenguajes o plataformas se ven afectados por CWE-1389?
MITRE lists the following affected platforms: Not Technology-Specific.
¿Cómo puedo prevenir 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…
¿Cómo detecta y corrige Plexicus CWE-1389?
El motor SAST de Plexicus detecta la firma de flujo de datos para CWE-1389 en cada commit. Cuando hay coincidencia, nuestro agente Codex Remedium abre un PR de corrección con el código corregido, las pruebas y un resumen de una línea para el revisor.
¿Dónde puedo aprender más sobre CWE-1389?
MITRE publica la definición canónica en https://cwe.mitre.org/data/definitions/1389.html. También puedes consultar la documentación de OWASP y NIST para guías relacionadas.
Weaknesses related to CWE-1389
Incorrect Type Conversion or Cast
This vulnerability occurs when software incorrectly changes data from one type to another, leading to unexpected behavior or security flaws.
Attempt to Access Child of a Non-structure Pointer
This vulnerability occurs when code incorrectly treats a pointer to a basic data type (like an integer) as if it points to a structured…
Incorrect Conversion between Numeric Types
This vulnerability occurs when a program converts a value from one numeric type to another (like a 64-bit integer to a 32-bit integer) and…
Access of Resource Using Incompatible Type ('Type Confusion')
Type confusion occurs when a program creates a resource—like a pointer, object, or variable—with one data type, but later incorrectly…
Further reading
- MITRE — CWE-1389 oficial https://cwe.mitre.org/data/definitions/1389.html
- Universal "netmask" npm package, used by 270,000+ projects, vulnerable to octal input data https://sick.codes/universal-netmask-npm-package-used-by-270000-projects-vulnerable-to-octal-input-data-server-side-request-forgery-remote-file-inclusion-local-file-inclusion-and-more-cve-2021-28918/
Deja de pagar por desarrollador.
Empieza a cerrar el bucle.
Plexicus es el ASPM nativo de IA que escanea, filtra, corrige, pentestea y explica — de forma autónoma. Desarrolladores ilimitados, repos ilimitados, acciones de IA de uso justo. Nivel gratuito real, €269/mo anual cuando estés listo.