CWE-348 使用不可信的源

Use of Less Trusted Source

结构: Simple

Abstraction: Base

状态: Draft

被利用可能性: unkown


The software 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_Nature: ChildOf cwe_CWE_ID: 345 cwe_View_ID: 1000 cwe_Ordinal: Primary

  • cwe_Nature: ChildOf cwe_CWE_ID: 345 cwe_View_ID: 699 cwe_Ordinal: Primary


Language: {'cwe_Class': 'Language-Independent', 'cwe_Prevalence': 'Undetermined'}


范围 影响 注释
Access Control ['Bypass Protection Mechanism', 'Gain Privileges or Assume Identity'] An attacker could utilize the untrusted data source to bypass protection mechanisms and gain access to sensitive data.


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 PHP

$requestingIP = '';
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {

$requestingIP = $_SERVER['REMOTE_ADDR'];

echo "You are not authorized to view this page";

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 PHP

$requestingIP = '';
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
echo "This application cannot be accessed through a proxy.";

$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.


标识 说明 链接
CVE-2001-0860 Product uses IP address provided by a client, instead of obtaining it from the packet headers, allowing easier spoofing.
CVE-2004-1950 Web 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.
BID:15326 Similar to CVE-2004-1950
CVE-2001-0908 Product logs IP address specified by the client instead of obtaining it from the packet headers, allowing information hiding.
CVE-2006-1126 PHP application uses IP address from X-Forwarded-For HTTP header, instead of REMOTE_ADDR.


映射的分类名 ImNode ID Fit Mapped Node Name
PLOVER Use of Less Trusted Source


  • CAPEC-141
  • CAPEC-142
  • CAPEC-73
  • CAPEC-76
  • CAPEC-85