Base · Medium

CWE-348: Use of Less Trusted Source

The product has two different sources of the same data or information, but it uses the source that has less support for verification, is less trusted, or is less resistant to attack.

CWE-348 · Base Level ·4 CVEs

Description

The product has two different sources of the same data or information, but it uses the source that has less support for verification, is less trusted, or is less resistant to attack.

Potential Impact

Access Control

Bypass Protection Mechanism, Gain Privileges or Assume Identity

Demonstrative Examples

This code attempts to limit the access of a page to certain IP Addresses. It checks the 'HTTP_X_FORWARDED_FOR' header in case an authorized user is sending the request through a proxy.
Bad
$requestingIP = '0.0.0.0';if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {$requestingIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
                     else{$requestingIP = $_SERVER['REMOTE_ADDR'];}
                     if(in_array($requestingIP,$ipAllowlist)){generatePage();return;}else{echo "You are not authorized to view this page";return;}
The 'HTTP_X_FORWARDED_FOR' header can be user controlled and so should never be trusted. An attacker can falsify the header to gain access to the page.
This fixed code only trusts the 'REMOTE_ADDR' header and so avoids the issue:
Good
$requestingIP = '0.0.0.0';if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {echo "This application cannot be accessed through a proxy.";return;
                     else{$requestingIP = $_SERVER['REMOTE_ADDR'];}
                     ...
Be aware that 'REMOTE_ADDR' can still be spoofed. This may seem useless because the server will send the response to the fake address and not the attacker, but this may still be enough to conduct an attack. For example, if the generatePage() function in this code is resource intensive, an attacker could flood the server with fake requests using an authorized IP and consume significant resources. This could be a serious DoS attack even though the attacker would never see the page's sensitive content.

Real-World CVE Examples

CVE IDDescription
CVE-2001-0860Product uses IP address provided by a client, instead of obtaining it from the packet headers, allowing easier spoofing.
CVE-2004-1950Web product uses the IP address in the X-Forwarded-For HTTP header instead of a server variable that uses the connecting IP address, allowing filter bypass.
CVE-2001-0908Product logs IP address specified by the client instead of obtaining it from the packet headers, allowing information hiding.
CVE-2006-1126PHP application uses IP address from X-Forwarded-For HTTP header, instead of REMOTE_ADDR.

Taxonomy Mappings

  • PLOVER: — Use of Less Trusted Source

Frequently Asked Questions

What is CWE-348?

CWE-348 (Use of Less Trusted Source) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. The product has two different sources of the same data or information, but it uses the source that has less support for verification, is less trusted, or is less resistant to attack.

How can CWE-348 be exploited?

Attackers can exploit CWE-348 (Use of Less Trusted Source) to bypass protection mechanism, gain privileges or assume identity. This weakness is typically introduced during the Architecture and Design, Implementation phase of software development.

How do I prevent CWE-348?

Follow secure coding practices, conduct code reviews, and use automated security testing tools (SAST/DAST) to detect this weakness early in the development lifecycle.

What is the severity of CWE-348?

CWE-348 is classified as a Base-level weakness (Medium abstraction). It has been observed in 4 real-world CVEs.