CWE-1389 Detail

CWE-1389

Incorrect Parsing of Numbers with Different Radices
Incomplete
2022-10-13 00:00 +00:00
2023-06-29 00:00 +00:00

Alerte pour un CWE

Stay informed of any changes for a specific CWE.
Alert management

Incorrect Parsing of Numbers with Different Radices

The product parses numeric input assuming base 10 (decimal) values, but it does not account for inputs that use a different base number (radix).

Extended Description

Frequently, a numeric input that begins with "0" is treated as octal, or "0x" causes it to be treated as hexadecimal, e.g. by the inet_addr() function. For example, "023" (octal) is 35 decimal, or "0x31" is 49 decimal. Other bases may be used as well. If the developer assumes decimal-only inputs, the code could produce incorrect numbers when the inputs are parsed using a different base. This can result in unexpected and/or dangerous behavior. For example, a "0127.0.0.1" IP address is parsed as octal due to the leading "0", whose numeric value would be the same as 87.0.0.1 (decimal), where the developer likely expected to use 127.0.0.1.

The consequences vary depending on the surrounding code in which this weakness occurs, but they can include bypassing network-based access control using unexpected IP addresses or netmasks, or causing apparently-symbolic identifiers to be processed as if they are numbers. In web applications, this can enable bypassing of SSRF restrictions.

Informations

Modes Of Introduction

Implementation : Input validation used may assume decimal bases during conditional checks, when it may not always be the case.
Implementation : The application may rely on a service that supports different numerical bases.

Applicable Platforms

Language

Class: Not Language-Specific (Undetermined)

Technologies

Class: Not Technology-Specific (Undetermined)

Common Consequences

Scope Impact Likelihood
ConfidentialityRead Application Data

Note: An attacker may use an unexpected numerical base to access private application resources.
Unknown
IntegrityBypass Protection Mechanism, Alter Execution Logic

Note: An attacker may use an unexpected numerical base to bypass or manipulate access control mechanisms.
Unknown

Observed Examples

Reference Description
CVE-2021-29662Chain: Use of zero-prepended IP addresses in Perl-based IP validation module can lead to an access control bypass.
CVE-2021-28918Chain: Use of zero-prepended IP addresses in a product that manages IP blocks can lead to an SSRF.
CVE-2021-29921Chain: Use of zero-prepended IP addresses in a Python standard library package can lead to an SSRF.
CVE-2021-29923Chain: Use of zero-prepended IP addresses in the net Golang library can lead to an access control bypass.
CVE-2021-29424Chain: Use of zero-prepended IP addresses in Perl netmask module allows bypass of IP-based access control.
CVE-2016-4029Chain: 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).
CVE-2020-13776Mishandling of hex-valued usernames leads to unexpected decimal conversion and privilege escalation in the systemd Linux suite.

Potential Mitigations

Phases : 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.
Phases : 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.
Phases : 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.

Vulnerability Mapping Notes

Rationale : This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.
Comments : Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.

References

REF-1284

Universal "netmask" npm package, used by 270,000+ projects, vulnerable to octal input data
Sick Codes.
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/

Submission

Name Organization Date Date Release Version
Anonymous External Contributor 2021-05-28 +00:00 2022-10-13 +00:00 4.9

Modifications

Name Organization Date Comment
CWE Content Team MITRE 2023-04-27 +00:00 updated Relationships, Time_of_Introduction
CWE Content Team MITRE 2023-06-29 +00:00 updated Mapping_Notes
Click on the button to the left (OFF), to authorize the inscription of cookie improving the functionalities of the site. Click on the button to the left (Accept all), to unauthorize the inscription of cookie improving the functionalities of the site.