CWE
Home > CWE List > COMPOSITE SLICE: CWE-98: Improper Control of Filename for Include/Require Statement in PHP Program ('PHP File Inclusion') (1.6)  

CWE-98: Improper Control of Filename for Include/Require Statement in PHP Program ('PHP File Inclusion')

 
Improper Control of Filename for Include/Require Statement in PHP Program ('PHP File Inclusion')
Definition in a New Window Definition in a New Window
Compound Element ID: 98 (Compound Element Base: Composite)Status: Draft
+ Description

Description Summary

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.

Extended Description

In certain versions and configurations of PHP, this can allow an attacker to specify a URL to a remote location from which the software 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.

+ Alternate Terms
PHP remote file inclusion
+ Time of Introduction
  • Implementation
+ Applicable Platforms

Languages

PHP

+ Observed Examples
ReferenceDescription
CVE-2004-0285Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request.
CVE-2004-0030Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request.
CVE-2004-0068Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request.
CVE-2005-2157Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request.
CVE-2005-2162Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request.
CVE-2005-2198Modification of assumed-immutable configuration variable in include file allows file inclusion via direct request.
CVE-2004-0128Modification of assumed-immutable variable in configuration script leads to file inclusion.
CVE-2005-1864PHP file inclusion.
CVE-2005-1869PHP file inclusion.
CVE-2005-1870PHP file inclusion.
CVE-2005-2154PHP local file inclusion.
CVE-2002-1704PHP remote file include.
CVE-2002-1707PHP remote file include.
CVE-2005-1964PHP remote file include.
CVE-2005-1681PHP remote file include.
CVE-2005-2086PHP remote file include.
CVE-2004-0127Directory traversal vulnerability in PHP include statement.
CVE-2005-1971Directory traversal vulnerability in PHP include statement.
CVE-2005-3335PHP 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.
+ Potential Mitigations
PhaseDescription

Assume all input is malicious. Use an appropriate combination of black lists and white lists to ensure only valid and expected input is processed by the system.

+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
CanPrecedeWeakness ClassWeakness Class94Failure to Control Generation of Code ('Code Injection')
Development Concepts (primary)699
Research Concepts1000
RequiresWeakness ClassWeakness Class216Containment Errors (Container Errors)
Research Concepts1000
RequiresWeakness BaseWeakness Base425Direct Request ('Forced Browsing')
Research Concepts1000
CanAlsoBeCompound Element: CompositeCompound Element: Composite426Untrusted Search Path
Research Concepts1000
RequiresWeakness BaseWeakness Base456Missing Initialization
Research Concepts1000
RequiresWeakness VariantWeakness Variant473PHP External Variable Modification
Research Concepts1000
ChildOfCategoryCategory632Weaknesses that Affect Files or Directories
Resource-specific Weaknesses (primary)631
ChildOfWeakness ClassWeakness Class706Use of Incorrectly-Resolved Name or Reference
Research Concepts (primary)1000
ChildOfCategoryCategory714OWASP Top Ten 2007 Category A3 - Malicious File Execution
Weaknesses in OWASP Top Ten (2007) (primary)629
ChildOfCategoryCategory727OWASP Top Ten 2004 Category A6 - Injection Flaws
Weaknesses in OWASP Top Ten (2004) (primary)711
CanFollowWeakness ClassWeakness Class73External Control of File Name or Path
Research Concepts1000
CanFollowWeakness BaseWeakness Base184Incomplete Blacklist
Research Concepts1000
+ Relationship Notes

This is frequently a functional consequence of other weaknesses. It is usually multi-factor with other factors (e.g. MAID), although not all inclusion bugs involve assumed-immutable data. Direct request weaknesses frequently play a role.

Can overlap directory traversal in local inclusion problems.

+ Research Gaps

Under-researched and under-reported. Other interpreted languages with "require" and "include" functionality could also product vulnerable applications, but as of 2007, PHP has been the focus. Any web-accessible language that uses executable file extensions is likely to have this type of issue, such as ASP, since .asp extensions are typically executable. Languages such as Perl are less likely to exhibit these problems because the .pl extension isn't always configured to be executable by the web server.

+ Affected Resources
  • File/Directory
+ Taxonomy Mappings
Mapped Taxonomy NameNode IDFitMapped Node Name
PLOVERPHP File Include
OWASP Top Ten 2007A3CWE More SpecificMalicious File Execution
+ References
Shaun Clowes. "A Study in Scarlet". <http://www.cgisecurity.com/lib/studyinscarlet.txt>.
+ Content History
Submissions
Submission DateSubmitterOrganizationSource
PLOVERExternally Mined
Modifications
Modification DateModifierOrganizationSource
2008-07-01Eric DalciCigitalExternal
updated Time of Introduction
2008-09-08CWE Content TeamMITREInternal
updated Relationships, Relationship Notes, Research Gaps, Taxonomy Mappings
2009-01-12CWE Content TeamMITREInternal
updated Relationships
2009-03-10CWE Content TeamMITREInternal
updated Relationships
2009-05-27CWE Content TeamMITREInternal
updated Description, Name
Composite Components
Composite Components
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
 
Containment Errors (Container Errors)
Definition in a New Window Definition in a New Window
Weakness ID: 216 (Weakness Class)Status: Incomplete
+ Description

Description Summary

This tries to cover various problems in which improper data are included within a "container."
+ Time of Introduction
  • Architecture and Design
  • Implementation
+ Applicable Platforms

Languages

All

+ Potential Mitigations
PhaseDescription

Compartmentalize your system to have "safe" areas where trust boundaries can be unambiguously drawn. Do not allow sensitive data to go outside of the trust boundary and always be careful when interfacing with a compartment outside of the safe area.

+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfCategoryCategory199Information Management Errors
Development Concepts (primary)699
ChildOfWeakness ClassWeakness Class485Insufficient Encapsulation
Research Concepts (primary)1000
RequiredByCompound Element: CompositeCompound Element: Composite61UNIX Symbolic Link (Symlink) Following
Research Concepts1000
RequiredByCompound Element: CompositeCompound Element: Composite98Improper Control of Filename for Include/Require Statement in PHP Program ('PHP File Inclusion')
Research Concepts1000
ParentOfWeakness VariantWeakness Variant219Sensitive Data Under Web Root
Development Concepts (primary)699
Research Concepts1000
ParentOfWeakness VariantWeakness Variant220Sensitive Data Under FTP Root
Development Concepts (primary)699
RequiredByCompound Element: CompositeCompound Element: Composite426Untrusted Search Path
Research Concepts1000
PeerOfCompound Element: CompositeCompound Element: Composite434Unrestricted File Upload
Research Concepts1000
ParentOfWeakness VariantWeakness Variant493Critical Public Variable Without Final Modifier
Research Concepts1000
+ Taxonomy Mappings
Mapped Taxonomy NameNode IDFitMapped Node Name
PLOVERContainment errors (container errors)
+ Maintenance Notes

This entry is closely associated with others related to encapsulation and permissions, and might ultimately prove to be a duplicate.

+ Content History
Submissions
Submission DateSubmitterOrganizationSource
PLOVERExternally Mined
Modifications
Modification DateModifierOrganizationSource
2008-07-01Eric DalciCigitalExternal
updated Time of Introduction
2008-09-08CWE Content TeamMITREInternal
updated Maintenance Notes, Relationships, Taxonomy Mappings
2009-05-27CWE Content TeamMITREInternal
updated Relationships
 
Direct Request ('Forced Browsing')
Definition in a New Window Definition in a New Window
Weakness ID: 425 (Weakness Base)Status: Incomplete
+ Description

Description Summary

The web application fails to adequately enforce appropriate authorization on all restricted URLs, scripts or files.

Extended Description

Web applications susceptible to direct request attacks often make the false assumption that such resources can only be reached through a given navigation path and so only apply authorization at certain points in the path.

+ Alternate Terms
forced browsing:

The "forced browsing" term could be misinterpreted to include weaknesses such as CSRF or XSS, so its use is discouraged.

+ Time of Introduction
  • Architecture and Design
  • Implementation
  • Operation
+ Applicable Platforms

Languages

All

+ Demonstrative Examples

Example 1

If forced browsing is possible, an attacker may be able to directly access a sensitive page by entering a URL similar to the following.

(Attack)
JSP
http://somesite.com/someapplication/admin.jsp
+ Observed Examples
ReferenceDescription
CVE-2004-2144Bypass authentication via direct request.
CVE-2005-1892Infinite loop or infoleak triggered by direct requests.
CVE-2004-2257Bypass auth/auth via direct request.
CVE-2005-1688Direct request leads to infoleak by error.
CVE-2005-1697Direct request leads to infoleak by error.
CVE-2005-1698Direct request leads to infoleak by error.
CVE-2005-1685Authentication bypass via direct request.
CVE-2005-1827Authentication bypass via direct request.
CVE-2005-1654Authorization bypass using direct request.
CVE-2005-1668Access privileged functionality using direct request.
CVE-2002-1798Upload arbitrary files via direct request.
+ Potential Mitigations
PhaseDescription

Apply appropriate access control authorizations for each access to all restricted URLs, scripts or files.

Consider using MVC based frameworks such as Struts.

+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfWeakness BaseWeakness Base288Authentication Bypass Using an Alternate Path or Channel
Development Concepts699
Research Concepts (primary)1000
ChildOfWeakness ClassWeakness Class424Failure to Protect Alternate Path
Development Concepts (primary)699
Research Concepts1000
CanPrecedeWeakness BaseWeakness Base471Modification of Assumed-Immutable Data (MAID)
Research Concepts1000
ChildOfCategoryCategory721OWASP Top Ten 2007 Category A10 - Failure to Restrict URL Access
Weaknesses in OWASP Top Ten (2007) (primary)629
ChildOfCategoryCategory722OWASP Top Ten 2004 Category A1 - Unvalidated Input
Weaknesses in OWASP Top Ten (2004)711
ChildOfCategoryCategory723OWASP Top Ten 2004 Category A2 - Broken Access Control
Weaknesses in OWASP Top Ten (2004) (primary)711
RequiredByCompound Element: CompositeCompound Element: Composite98Improper Control of Filename for Include/Require Statement in PHP Program ('PHP File Inclusion')
Research Concepts1000
PeerOfWeakness BaseWeakness Base288Authentication Bypass Using an Alternate Path or Channel
Research Concepts1000
+ Relationship Notes

Overlaps Modification of Assumed-Immutable Data (MAID), authorization errors, container errors; often primary to other weaknesses such as XSS and SQL injection.

+ Theoretical Notes

"Forced browsing" is a step-based manipulation involving the omission of one or more steps, whose order is assumed to be immutable. The application does not verify that the first step was performed successfully before the second step. The consequence is typically "authentication bypass" or "path disclosure," although it can be primary to all kinds of weaknesses, especially in languages such as PHP, which allow external modification of assumed-immutable variables.

+ Taxonomy Mappings
Mapped Taxonomy NameNode IDFitMapped Node Name
PLOVERDirect Request aka 'Forced Browsing'
OWASP Top Ten 2007A10CWE More SpecificFailure to Restrict URL Access
OWASP Top Ten 2004A1CWE More SpecificUnvalidated Input
OWASP Top Ten 2004A2CWE More SpecificBroken Access Control
+ Content History
Submissions
Submission DateSubmitterOrganizationSource
PLOVERExternally Mined
Modifications
Modification DateModifierOrganizationSource
2008-07-01Sean EidemillerCigitalExternal
added/updated demonstrative examples
2008-07-01Eric DalciCigitalExternal
updated Potential Mitigations, Time of Introduction
2008-08-15VeracodeExternal
Suggested OWASP Top Ten 2004 mapping
2008-09-08CWE Content TeamMITREInternal
updated Alternate Terms, Relationships, Relationship Notes, Taxonomy Mappings, Theoretical Notes
2008-10-14CWE Content TeamMITREInternal
updated Description
 
Missing Initialization
Definition in a New Window Definition in a New Window
Weakness ID: 456 (Weakness Base)Status: Draft
+ Description

Description Summary

The software does not initialize critical variables, which causes the execution environment to use unexpected values.
+ Time of Introduction
  • Implementation
+ Applicable Platforms

Languages

All

+ Demonstrative Examples

Example 1

Here, an uninitialized field in a Java class is used in a seldom-called method, which would cause a NullPointerException to be thrown.

(Bad Code)
Java
private User user;
public void someMethod() {
// Do something interesting.
...
// Throws NPE if user hasn't been properly initialized.
String username = user.getName();
}
+ Observed Examples
ReferenceDescription
CVE-2005-2978Product uses uninitialized variables for size and index, leading to resultant buffer overflow.
CVE-2005-2109Internal variable in PHP application is not initialized, allowing external modification.
CVE-2005-2193Array variable not initialized in PHP application, leading to resultant SQL injection.
+ Potential Mitigations
PhaseDescription

Check that critical variables are initialized.

Use a static analysis tool to spot non-initialized variables.

+ Other Notes

This weakness is a major factor in a number of resultant weaknesses, especially in web applications that allow global variable initialization (such as PHP) with libraries that can be directly requested.

+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
CanPrecedeWeakness BaseWeakness Base89Improper Sanitization of Special Elements used in an SQL Command ('SQL Injection')
Research Concepts1000
CanPrecedeCompound Element: CompositeCompound Element: Composite120Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
Research Concepts1000
ChildOfCategoryCategory452Initialization and Cleanup Errors
Development Concepts (primary)699
ChildOfWeakness BaseWeakness Base665Improper Initialization
Research Concepts (primary)1000
RequiredByCompound Element: CompositeCompound Element: Composite98Improper Control of Filename for Include/Require Statement in PHP Program ('PHP File Inclusion')
Research Concepts1000
CanAlsoBeWeakness BaseWeakness Base454External Initialization of Trusted Variables
Research Concepts1000
ParentOfWeakness VariantWeakness Variant457Use of Uninitialized Variable
Development Concepts (primary)699
Research Concepts (primary)1000
+ Research Gaps

It is highly likely that a large number of resultant weaknesses have missing initialization as a primary factor, but researcher reports generally do not provide this level of detail.

+ Taxonomy Mappings
Mapped Taxonomy NameNode IDFitMapped Node Name
PLOVERMissing Initialization
+ Content History
Submissions
Submission DateSubmitterOrganizationSource
PLOVERExternally Mined
Modifications
Modification DateModifierOrganizationSource
2008-07-01Sean EidemillerCigitalExternal
added/updated demonstrative examples
2008-07-01Eric DalciCigitalExternal
updated Potential Mitigations, Time of Introduction
2008-09-08CWE Content TeamMITREInternal
updated Relationships, Other Notes, Taxonomy Mappings
 
PHP External Variable Modification
Definition in a New Window Definition in a New Window
Weakness ID: 473 (Weakness Variant)Status: Draft
+ Description

Description Summary

A PHP application does not properly protect against the modification of variables from external sources, such as query parameters or cookies. This can expose the application to numerous weaknesses that would not exist otherwise.
+ Time of Introduction
  • Implementation
+ Applicable Platforms

Languages

PHP

+ Observed Examples
ReferenceDescription
CVE-2000-0860File upload allows arbitrary file read by setting hidden form variables to match internal variable names.
CVE-2001-0854Mistakenly trusts $PHP SELF variable to determine if include script was called by its parent.
CVE-2002-0764PHP remote file inclusion by modified assumed-immutable variable.
CVE-2001-1025Modify key variable when calling scripts that don't load a library that initializes it.
CVE-2003-0754Authentication bypass by modifying array used for authentication.
+ Potential Mitigations
PhaseDescription

Carefully identify which variables can be controlled or influenced by an external user, and consider adopting a naming convention to emphasize when externally modifiable variables are being used. An application should be reluctant to trust variables that have been initialized outside of its trust boundary. Ensure adequate checking is performed when relying on input from outside a trust boundary. Do not allow your application to run with register_globals enabled. If you implement a register_globals emulator, be extremely careful of variable extraction, dynamic evaluation, and similar issues, since weaknesses in your emulation could allow external variable modification to take place even without register_globals.

+ Other Notes

This is a language-specific instance of Modification of Assumed-Immutable Data (MAID). This can be resultant from direct request (alternate path) issues. It can be primary to weaknesses such as PHP file inclusion, SQL injection, XSS, authentication bypass, and others.

+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
CanPrecedeCompound Element: CompositeCompound Element: Composite98Improper Control of Filename for Include/Require Statement in PHP Program ('PHP File Inclusion')
Research Concepts1000
ChildOfWeakness BaseWeakness Base471Modification of Assumed-Immutable Data (MAID)
Development Concepts (primary)699
Research Concepts (primary)1000
RequiredByCompound Element: CompositeCompound Element: Composite98Improper Control of Filename for Include/Require Statement in PHP Program ('PHP File Inclusion')
Research Concepts1000
PeerOfWeakness VariantWeakness Variant616Incomplete Identification of Uploaded File Variables (PHP)
Research Concepts1000
+ Taxonomy Mappings
Mapped Taxonomy NameNode IDFitMapped Node Name
PLOVERPHP External Variable Modification
+ Content History
Submissions
Submission DateSubmitterOrganizationSource
PLOVERExternally Mined
Modifications
Modification DateModifierOrganizationSource
2008-07-01Eric DalciCigitalExternal
updated Time of Introduction
2008-09-08CWE Content TeamMITREInternal
updated Relationships, Other Notes, Taxonomy Mappings
Page Last Updated: October 29, 2009