CWEweakness

CWE-98 Improper Control of Filename for Include/Require Statement in PHP Program

High Official page ↗
Alternate terms
Remote file include, RFI, Local file inclusion, PHP Remote File Inclusion
Abstraction
Variant
Structure
Simple
Status
Draft
Likelihood of exploit
High
Languages
PHP
CWE version
5.0

Description

The PHP application receives input from an upstream component, but it does not restrict or incorrectly restricts the input before its usage in "require," "include," or similar functions.

Common consequences

• Integrity, Confidentiality, Availability: Execute Unauthorized Code or Commands — In certain versions and configurations of PHP with the allow_url_include setting enabled, an attacker could specify a URL to a remote location from which the product will obtain the code to execute. In other cases in association with path traversal, the attacker can specify a local file that may contain executable statements that can be parsed by PHP. In some cases, the attacker might be able to insert PHP specifiers into a data file, then cause that data file to be included, causing it to be parsed by PHP.

Potential mitigations

• [Architecture and Design] Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid [REF-1482]. • [Architecture and Design] When the set of acceptable objects, such as filenames or URLs, is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames or URLs, and reject all other inputs. For example, ID 1 could map to "inbox.txt" and ID 2 could map to "profile.txt". Features such as the ESAPI AccessReferenceMap [REF-185] provide this capability. • [Architecture and Design] For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server. • [Architecture and Design, Operation] Run the code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which files can be accessed in a particular directory or which commands can be executed by the software. OS-level examples include the Unix chroot jail, AppArmor, and SELinux. In general, managed code may provide some protection. For example, java.io.FilePermission in the Java SecurityManager allows the software to specify restrictions on file operations. This may not be a feasible solution, and it only limits the impact to the operating system; the rest of the application may still be subject to compromise. Be careful to avoid CWE-243 and other weaknesses related to jails. • [Architecture and Design, Operation] Run your code using the lowest privileges that are required to accomplish the necessary tasks [REF-76]. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need to run as the database administrator, especially in day-to-day operations. • [Implementation] Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright. When validating filenames, use stringent lists that limit the character set to be used. If feasible, only allow a single "." character in the filename to avoid weaknesses such as CWE-23, and exclude directory separators such as "/" to avoid CWE-36. Use a list of allowable file extensions, which will help to avoid CWE-434. Do not rely exclusively on a filtering mechanism that removes potentially dangerous characters. This is equivalent to a denylist, which may be incomplete (CWE-184). For example, filtering "/" is insufficient protection if the filesystem also supports the use of "\" as a directory separator. Another possible error could occur when the filtering is applied in a way that still produces dangerous data (CWE-182). For example, if "../" sequences are removed from the ".../...//" string in a sequential fashion, two instances of "../" would be removed from the original string, but the remaining characters would still form the "../" string. • [Architecture and Design, Operation] Store library, include, and utility files outside of the web document root, if possible. Otherwise, store them in a separate directory and use the web server's access control capabilities to prevent attackers from directly requesting them. One common practice is to define a fixed constant in each calling program, then check for the existence of the constant in the library/include file; if the constant does not exist, then the file was directly requested, and it can exit immediately. This significantly reduces the chance of an attacker being able to bypass any protection mechanisms that are in the base program but not in the include files. It will also reduce the attack surface. • [Architecture and Design, Implementation] Understand all the potential areas where untrusted inputs can enter your software: parameters or arguments, cookies, anything read from the network, environment variables, reverse DNS lookups, query results, request headers, URL components, e-mail, files, filenames, databases, and any external systems that provide data to the application. Remember that such inputs may be obtained indirectly through API calls. Many file inclusion problems occur because the programmer assumed that certain inputs could not be modified, especially for cookies and URL components. • [Operation] Use an application firewall that can detect attacks against this weakness. It can be beneficial in cases in which the code cannot be fixed (because it is controlled by a third party), as an emergency prevention measure while more comprehensive software assurance measures are applied, or to provide defense in depth [REF-1481]. • [Operation, Implementation] Ensure that the allow_url_include setting is off. Refactor the code if necessary. • [Operation, Implementation] Develop and run the code in the most recent versions of PHP available. Many of the highly risky features in earlier PHP interpreters have been removed, restricted, or disabled by default. • [Operation, Implementation] When using PHP, configure the application so that it does not use register_globals. During implementation, develop the application so that it does not rely on this feature, but be wary of implementing a register_globals emulation that is subject to weaknesses such as CWE-95, CWE-621, and similar issues. Often, programmers do not protect direct access to files intended only to be included by core programs. These include files may assume that critical variables have already been initialized by the calling program. As a result, the use of register_globals combined with the ability to directly access the include file may allow attackers to conduct file inclusion attacks. This remains an extremely common pattern as of 2009. • [Operation] Set allow_url_fopen to false, which limits the ability to include files from remote locations.

Detection methods

• Manual Analysis: Manual white-box analysis can be very effective for finding this issue, since there is typically a relatively small number of include or require statements in each program. • Automated Static Analysis: The external control or influence of filenames can often be detected using automated static analysis that models data flow within the product. Automated static analysis might not be able to recognize when proper input validation is being performed, leading to false positives - i.e., warnings that do not have any security consequences or require any code changes. If the program uses a customized input validation library, then some tools may allow the analyst to create custom signatures to detect usage of those routines.

Observed examples

• CVE-2004-0285: Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request. • CVE-2004-0030: Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request. • CVE-2004-0068: Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request. • CVE-2005-2157: Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request. • CVE-2005-2162: Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request. • CVE-2005-2198: Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request. • CVE-2004-0128: Modification of assumed-immutable variable in configuration script leads to file inclusion. • CVE-2005-1864: PHP file inclusion. • CVE-2005-1869: PHP file inclusion. • CVE-2005-1870: PHP file inclusion. • CVE-2005-2154: PHP local file inclusion. • CVE-2002-1704: PHP remote file include. • CVE-2002-1707: PHP remote file include. • CVE-2005-1964: PHP remote file include. • CVE-2005-1681: PHP remote file include. • CVE-2005-2086: PHP remote file include. • CVE-2004-0127: Directory traversal vulnerability in PHP include statement. • CVE-2005-1971: Directory traversal vulnerability in PHP include statement. • CVE-2005-3335: PHP file inclusion issue, both remote and local; local include uses ".." and "%00" characters as a manipulation, but many remote file inclusion issues probably have this vector. • CVE-2009-1936: Chain: library file sends a redirect if it is directly requested but continues to execute, allowing remote file inclusion and path traversal.

Related

Attack pattern · CAPEC (1)

  • CAPEC-193 PHP Remote File Inclusion attack pattern

Observed example · CVE (20)

  • CVE-2009-1936 _functions.php in cpCommerce 1.2.x, possibly including 1.2.9, sends a redirect but does not exit when it is called directly, which allows… vulnerability
  • CVE-2005-3335 PHP file inclusion vulnerability in bug_sponsorship_list_view_inc.php in Mantis 1.0.0RC2 and 0.19.2 allows remote attackers to execute… vulnerability
  • CVE-2005-2198 PHP remote file inclusion vulnerability in lang.php in SPiD before 1.3.1 allows remote attackers to execute arbitrary code via the… vulnerability
  • CVE-2005-2154 PHP local file inclusion vulnerability in (1) view.php and (2) open.php in osTicket 1.3.1 beta and earlier allows remote attackers to… vulnerability
  • CVE-2005-2157 PHP remote file inclusion vulnerability in survey.inc.php for nabopoll 1.2 allows remote attackers to execute arbitrary PHP code via the… vulnerability
  • CVE-2005-2162 PHP remote file inclusion vulnerability in form.inc.php3 in MyGuestbook 0.6.1 allows remote attackers to execute arbitrary PHP code via the… vulnerability
  • CVE-2005-2086 PHP remote file inclusion vulnerability in viewtopic.php in phpBB 2.0.15 and earlier allows remote attackers to execute arbitrary PHP code. vulnerability
  • CVE-2005-1971 Directory traversal vulnerability in InteractivePHP FusionBB .11 Beta and earlier allows remote attackers to include arbitrary local files… vulnerability
  • CVE-2005-1864 PHP remote file inclusion vulnerability in cal_admintop.php in Calendarix Advanced 1.5 allows remote attackers to execute arbitrary PHP… vulnerability
  • CVE-2005-1870 PHP remote file inclusion vulnerability in childwindow.inc.php in Popper 1.41-r2 and earlier allows remote attackers to execute arbitrary… vulnerability
  • CVE-2005-1964 PHP remote file inclusion vulnerability in utilit.php for Ovidentia Portal allows remote attackers to execute arbitrary PHP code via the… vulnerability
  • CVE-2005-1869 PHP remote file inclusion vulnerability in start_lobby.php in MWChat 6.x allows remote attackers to execute arbitrary PHP code via the… vulnerability
  • CVE-2005-1681 PHP remote file inclusion vulnerability in common.php in phpATM 1.21, and possibly earlier versions, allows remote attackers to execute… vulnerability
  • CVE-2004-0285 PHP remote file inclusion vulnerabilities in include/footer.inc.php in (1) AllMyVisitors, (2) AllMyLinks, and (3) AllMyGuests allow remote… vulnerability
  • CVE-2004-0127 Directory traversal vulnerability in editconfig_gedcom.php for phpGedView 2.65.1 and earlier allows remote attackers to read arbitrary… vulnerability
  • CVE-2004-0128 PHP remote file inclusion vulnerability in the GEDCOM configuration script for phpGedView 2.65.1 and earlier allows remote attackers to… vulnerability
  • CVE-2004-0068 PHP remote file inclusion vulnerability in config.php for PhpDig 1.6.5 and earlier allows remote attackers to execute arbitrary PHP code by… vulnerability
  • CVE-2004-0030 PHP remote file inclusion vulnerability in (1) functions.php, (2) authentication_index.php, and (3) config_gedcom.php for PHPGEDVIEW 2.61… vulnerability
  • CVE-2002-1704 Zeroboard 4.1, when the "allow_url_fopen" and "register_globals" variables are enabled, allows remote attackers to execute arbitrary PHP… vulnerability
  • CVE-2002-1707 install.php in phpBB 2.0 through 2.0.1, when "allow_url_fopen" and "register_globals" variables are set to "on", allows remote attackers to… vulnerability

Can also be · CWE (1)

  • CWE-426 Untrusted Search Path weakness

Can precede · CWE (1)

  • CWE-94 Improper Control of Generation of Code weakness

Child of · CWE (2)

  • CWE-706 Use of Incorrectly-Resolved Name or Reference weakness
  • CWE-829 Inclusion of Functionality from Untrusted Control Sphere weakness

Referenced by CAPEC · weakness (1)

  • CAPEC-193 PHP Remote File Inclusion attack pattern

Referenced by CVE · weakness (1,351)

  • CVE-2014-125137 C97net qEngine CMS through 6.0.0, Kemana Directory through 1.5.6, and Cart Engine through 3.0.0 contain a local file inclusion… vulnerability
  • CVE-2026-110185 The Bit Flows: AI Agent Automation & Integrations for Forms, CRM, eCommerce, Google Sheets, and More plugin for WordPress is vulnerable to… vulnerability
  • CVE-2026-112850 Improper Control of Filename for Include/Require Statement in PHP Program ('PHP Remote File Inclusion') vulnerability in AncoraThemes Your… vulnerability
  • CVE-2017-20289 Broadstreet Ad Widget plugin for WordPress 2.2.0 before 2.12.0 contains a local file inclusion vulnerability that allows authenticated… vulnerability
  • CVE-2026-112820 Improper Control of Filename for Include/Require Statement in PHP Program ('PHP Remote File Inclusion') vulnerability in Elated-Themes… vulnerability
  • CVE-2026-112832 Improper Control of Filename for Include/Require Statement in PHP Program ('PHP Remote File Inclusion') vulnerability in CozyThemes… vulnerability
  • CVE-2016-20101 Issuu Panel plugin for WordPress before 1.6.6 contains a PHP file inclusion vulnerability that allows unauthenticated attackers to include… vulnerability
  • CVE-2026-113402 ArmorX Spam developed by ArmorX Global Technology has a Local File Inclusion vulnerability. vulnerability
  • CVE-2026-111829 Improper Control of Filename for Include/Require Statement in PHP Program ('PHP Remote File Inclusion') vulnerability in WP Mailster WP… vulnerability
  • CVE-2026-103367 The ShopMagic – email automation for WordPress plugin for WordPress is vulnerable to Local File Inclusion in all versions up to, and… vulnerability
  • CVE-2026-104909 The Mang Board plugin for WordPress is vulnerable to Local File Inclusion in all versions up to, and including, 2.4.3 via the '<mode>_type… vulnerability
  • CVE-2026-104995 The BP Profile Search plugin for WordPress is vulnerable to Local File Inclusion in versions up to, and including, 5.9 via the… vulnerability
  • CVE-2026-110284 The LifterLMS – WP LMS for eLearning, Online Courses, & Quizzes plugin for WordPress is vulnerable to Local File Inclusion in versions up… vulnerability
  • CVE-2026-62858 YOURLS is a self-hosted, customizable URL shortener written in PHP. vulnerability
  • CVE-2026-104899 The GeoDirectory – WP Business Directory Plugin and Classified Listings Directory plugin for WordPress is vulnerable to Local File… vulnerability
  • CVE-2026-42704 Unauthenticated Local File Inclusion in Kids Care <= 3.2.4 versions. vulnerability
  • CVE-2026-42724 Unauthenticated Local File Inclusion in CleanSkin <= 1.5.0 versions. vulnerability
  • CVE-2026-42777 Unauthenticated Local File Inclusion in Aalto <= 1.8 versions. vulnerability
  • CVE-2026-48193 Unauthenticated Local File Inclusion in Uminex <= 1.0.9 versions. vulnerability
  • CVE-2026-48194 Unauthenticated Local File Inclusion in DukaMarket <= 1.3.0 versions. vulnerability
  • CVE-2026-62020 Unauthenticated Local File Inclusion in TouchUp < 1.4 versions. vulnerability
  • CVE-2026-62032 Unauthenticated Local File Inclusion in DirectoryPress <= 3.6.27 versions. vulnerability
  • CVE-2026-62065 Unauthenticated Local File Inclusion in Cardea <= 2.3 versions. vulnerability
  • CVE-2026-62066 Unauthenticated Local File Inclusion in Volos <= 1.2 versions. vulnerability
  • CVE-2026-62067 Unauthenticated Local File Inclusion in Kaven <= 1.2 versions. vulnerability
  • CVE-2026-62068 Unauthenticated Local File Inclusion in Teoro <= 1.1 versions. vulnerability
  • CVE-2026-62069 Unauthenticated Local File Inclusion in Fabius <= 1.0 versions. vulnerability
  • CVE-2026-62070 Unauthenticated Local File Inclusion in Flipmart <= 2.8 versions. vulnerability
  • CVE-2026-62074 Unauthenticated Local File Inclusion in Ozeum <= 1.3.0 versions. vulnerability
  • CVE-2026-62075 Unauthenticated Local File Inclusion in Backhoe <= 2.0 versions. vulnerability
Show all 1,351 ›

Referenced by CWE · can precede (5)

  • CWE-184 Incomplete List of Disallowed Inputs weakness
  • CWE-425 Direct Request weakness
  • CWE-456 Missing Initialization of a Variable weakness
  • CWE-473 PHP External Variable Modification weakness
  • CWE-73 External Control of File Name or Path weakness

Referenced by OWASP · mapped cwe (2)