[Forgot Password]
Login  Register Subscribe

30479

 
 

423868

 
 

248149

 
 

909

 
 

194803

 
 

282

Paid content will be excluded from the download.


Download | Alert*
CWE
view XML

External Control of Critical State Data

ID: 642Date: (C)2012-05-14   (M)2022-10-10
Type: weaknessStatus: DRAFT
Abstraction Type: Class





Description

The software stores security-critical state information about its users, or the software itself, in a location that is accessible to unauthorized actors.

Extended Description

If an attacker can modify the state information without detection, then it could be used to perform unauthorized actions or access unexpected resources, since the application programmer does not expect that the state can be changed.

State information can be stored in various locations such as a cookie, in a hidden web form field, input parameter or argument, an environment variable, a database record, within a settings file, etc. All of these locations have the potential to be modified by an attacker. When this state information is used to control security or determine resource usage, then it may create a vulnerability. For example, an application may perform authentication, then save the state in an "authenticated=true" cookie. An attacker may simply create this cookie in order to bypass the authentication.

Enabling Factors for Exploitation
An application maintains its own state and/or user state (i.e. application is stateful).
State information can be affected by the user of an application through some means other than the legitimate state transitions (e.g. logging into the system, purchasing an item, making a payment, etc.)
An application does not have means to detect state tampering and behave in a fail safe manner.

Likelihood of Exploit: High

Applicable Platforms
Language Class: All
Technology Class: Often
Technology Class: Web-Server

Time Of Introduction

  • Architecture and Design
  • Implementation

Related Attack Patterns

Common Consequences

ScopeTechnical ImpactNotes
Access_Control
 
Bypass protection mechanism
Gain privileges / assume identity
 
An attacker could potentially modify the state in malicious ways. If the state is related to the privileges or level of authentication that the user has, then state modification might allow the user to bypass authentication or elevate privileges.
 
Confidentiality
 
Read application data
 
The state variables may contain sensitive information that should not be known by the client.
 
Availability
 
DoS: crash / exit / restart
 
By modifying state variables, the attacker could violate the application's expectations for the contents of the state, leading to a denial of service due to an unexpected error condition.
 

Detection Methods
None

Potential Mitigations

PhaseStrategyDescriptionEffectivenessNotes
Architecture and Design
 
 Understand all the potential locations that are accessible to attackers. For example, some programmers assume that cookies and hidden form fields cannot be modified by an attacker, or they may not consider that environment variables can be modified before a privileged program is invoked.
 
  
Architecture and Design
 
Identify and Reduce Attack Surface
 
Store state information and sensitive data on the server side only.
Ensure that the system definitively and unambiguously keeps track of its own state and user state and has rules defined for legitimate state transitions. Do not allow any application user to affect state directly in any way other than through legitimate actions leading to state transitions.
If information must be stored on the client, do not do so without encryption and integrity checking, or otherwise having a mechanism on the server side to catch tampering. Use a message authentication code (MAC) algorithm, such as Hash Message Authentication Code (HMAC) [R.642.2]. Apply this against the state or sensitive data that you have to expose, which can guarantee the integrity of the data - i.e., that the data has not been modified. Ensure that you use an algorithm with a strong hash function (CWE-328).
 
  
Architecture and Design
 
 Store state information on the server side only. Ensure that the system definitively and unambiguously keeps track of its own state and user state and has rules defined for legitimate state transitions. Do not allow any application user to affect state directly in any way other than through legitimate actions leading to state transitions.
 
  
Architecture and Design
 
Libraries or Frameworks
 
Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.
With a stateless protocol such as HTTP, use some frameworks can maintain the state for you.
Examples include ASP.NET View State and the OWASP ESAPI Session Management feature.
Be careful of language features that provide state support, since these might be provided as a convenience to the programmer and may not be considering security.
 
  
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.
 
  
Operation
Implementation
 
Environment Hardening
 
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.
 
  
Testing
 
 Use automated static analysis tools that target this type of weakness. Many modern techniques use data flow analysis to minimize the number of false positives. This is not a perfect solution, since 100% accuracy and coverage are not feasible.
 
  
Testing
 
 Use dynamic tools and techniques that interact with the software using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results.
 
  
Testing
 
 Use tools and techniques that require manual (human) analysis, such as penetration testing, threat modeling, and interactive tools that allow the tester to record and modify an active session. These may be more effective than strictly automated techniques. This is especially the case with weaknesses that are related to design and business rules.
 
  

Relationships

Related CWETypeViewChain
CWE-642 ChildOf CWE-895 Category CWE-888  

Demonstrative Examples   (Details)

  1. In the following example, an authentication flag is read from a browser cookie, thus allowing for external control of user state data.
  2. The following code segment implements a basic server that uses the "ls" program to perform a directory listing of the directory that is listed in the "HOMEDIR" environment variable. The code intends to allow the user to specify an alternate "LANG" environment variable. This causes "ls" to customize its output based on a given language, which is an important capability when supporting internationalization.
  3. The following code uses input from a configuration file to determine which file to open and echo back to the user. If the program runs with privileges and malicious users can change the configuration file, they can use the program to read any file on the system that ends with the extension .txt. (Demonstrative Example Id DX-66)
  4. The following code uses input from an HTTP request to create a file name. The programmer has not considered the possibility that an attacker could provide a file name such as "../../tomcat/conf/server.xml", which causes the application to delete one of its own configuration files (CWE-22). (Demonstrative Example Id DX-65)
  5. This code prints all of the running processes belonging to the current user. (Demonstrative Example Id DX-68)
  6. This program is intended to execute a command that lists the contents of a restricted directory, then performs other actions. Assume that it runs with setuid privileges in order to bypass the permissions check by the operating system. (Demonstrative Example Id DX-67)

Observed Examples

  1. CVE-2005-2428 : Mail client stores password hashes for unrelated accounts in a hidden form field.
  2. CVE-2008-0306 : Privileged program trusts user-specified environment variable to modify critical configuration settings.
  3. CVE-1999-0073 : Telnet daemon allows remote clients to specify critical environment variables for the server, leading to code execution.
  4. CVE-2007-4432 : Untrusted search path vulnerability through modified LD_LIBRARY_PATH environment variable.
  5. CVE-2006-7191 : Untrusted search path vulnerability through modified LD_LIBRARY_PATH environment variable.
  6. CVE-2008-5738 : Calendar application allows bypass of authentication by setting a certain cookie value to 1.
  7. CVE-2008-5642 : Setting of a language preference in a cookie enables path traversal attack.
  8. CVE-2008-5125 : Application allows admin privileges by setting a cookie value to "admin."
  9. CVE-2008-5065 : Application allows admin privileges by setting a cookie value to "admin."
  10. CVE-2008-4752 : Application allows admin privileges by setting a cookie value to "admin."
  11. CVE-2000-0102 : Shopping cart allows price modification via hidden form field.
  12. CVE-2000-0253 : Shopping cart allows price modification via hidden form field.
  13. CVE-2008-1319 : Server allows client to specify the search path, which can be modified to point to a program that the client has uploaded.

For more examples, refer to CVE relations in the bottom box.

White Box Definitions
None

Black Box Definitions
None

Taxynomy Mappings
None

References:

  1. OWASP .Top 10 2007-Insecure Direct Object Reference. Published on 2007.
  2. .HMAC. Wikipedia. 2011-08-18.
  3. Michael Howard David LeBlanc John Viega .24 Deadly Sins of Software Security. McGraw-Hill. Section:'"Sin 4: Use of Magic URLs, Predictable Cookies, and Hidden Form Fields." Page 75'. Published on 2010.
CVE    2
CVE-2017-0928
CVE-2018-15382

© SecPod Technologies