Reliance on Untrusted Inputs in a Security Decision |
Weakness ID: 807 (Weakness Base) | Status: Incomplete |
Description Summary
Extended Description
Developers may assume that inputs such as cookies, environment variables, and hidden form fields cannot be modified. However, an attacker could change these inputs using customized clients or other attacks. This change might not be detected. When security decisions such as authentication and authorization are made based on the values of these inputs, attackers can bypass the security of the software.
Without sufficient encryption, integrity checking, or other mechanism, any input that originates from an outsider cannot be trusted.
Scope | Effect |
---|---|
Confidentiality Integrity Availability | Technical Impact: Bypass security; Gain privileges Attackers can bypass the security decision to access whatever is being protected. The consequences will depend on the associated functionality, but they can range from granting additional privileges to untrusted users to bypassing important security checks. Ultimately, this weakness may lead to exposure or modification of sensitive data, system crash, or execution of arbitrary code. |
Manual Static Analysis Since this weakness does not typically appear frequently within a single software package, manual white box techniques may be able to provide sufficient code coverage and reduction of false positives if all potentially-vulnerable operations can be assessed within limited time constraints. Effectiveness: High The effectiveness and speed of manual analysis will be reduced if the there is not a centralized security mechanism, and the security logic is widely distributed throughout the software. |
Example 1
The following code excerpt reads a value from a browser cookie to determine the role of the user.
Example 2
The following code could be for a medical records application. It performs authentication by checking if a cookie has been set.
The programmer expects that the AuthenticateUser() check will always be applied, and the "authenticated" cookie will only be set when authentication succeeds. The programmer even diligently specifies a 2-hour expiration for the cookie.
However, the attacker can set the "authenticated" cookie to a non-zero value such as 1. As a result, the $auth variable is 1, and the AuthenticateUser() check is not even performed. The attacker has bypassed the authentication.
Example 3
In the following example, an authentication flag is read from a browser cookie, thus allowing for external control of user state data.
Reference | Description |
---|---|
CVE-2009-1549 | Attacker can bypass authentication by setting a cookie to a specific value. |
CVE-2009-1619 | Attacker can bypass authentication and gain admin privileges by setting an "admin" cookie to 1. |
CVE-2009-0864 | Content management system allows admin privileges by setting a "login" cookie to "OK." |
CVE-2008-5784 | e-dating application allows admin privileges by setting the admin cookie to 1. |
CVE-2008-6291 | Web-based email list manager allows attackers to gain admin privileges by setting a login cookie to "admin." |
Phase: Architecture and Design Do not keep state information on the client without using encryption and integrity checking, or otherwise having a mechanism on the server side to catch state tampering. Use a message authentication code (MAC) algorithm, such as Hash Message Authentication Code (HMAC). Apply this against the state 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). |
Phase: 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. |
Phase: 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. With a stateless protocol such as HTTP, use a framework that maintains 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. |
Phase: 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. |
Phases: Operation; Implementation If you are using PHP, configure your application so that it does not use register_globals. During implementation, develop your 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. |
Phases: Architecture and Design; Implementation Strategy: Identify and Reduce Attack Surface 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, databases, and any external systems that provide data to the application. Remember that such inputs may be obtained indirectly through API calls. Identify all inputs that are used for security decisions and determine if you can modify the design so that you do not have to rely on submitted inputs at all. For example, you may be able to keep critical information about the user's session on the server side instead of recording it within external data. |
Nature | Type | ID | Name | View(s) this relationship pertains to |
---|---|---|---|---|
ChildOf | Category | 254 | Security Features | Development Concepts (primary)699 |
ChildOf | Weakness Class | 693 | Protection Mechanism Failure | Research Concepts (primary)1000 |
ChildOf | Category | 803 | 2010 Top 25 - Porous Defenses | Weaknesses in the 2010 CWE/SANS Top 25 Most Dangerous Programming Errors (primary)800 |
ParentOf | Weakness Variant | 247 | Reliance on DNS Lookups in a Security Decision | Research Concepts (primary)1000 |
ParentOf | Weakness Variant | 302 | Authentication Bypass by Assumed-Immutable Data | Research Concepts1000 |
ParentOf | Weakness Variant | 784 | Reliance on Cookies without Validation and Integrity Checking in a Security Decision | Research Concepts1000 |
CAPEC-ID | Attack Pattern Name | (CAPEC Version: 1.4) |
---|---|---|
232 | Exploitation of Privilege/Trust |