---
title: "CWE-642: External Control of Critical State Data"
url: https://radicalnotion.ai/cwe/cwe-642
type: cwe
description: "The product stores security-critical state information about its users, or the product itself, in a location that is accessible to unauthorized actors."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-642: External Control of Critical State Data

- **Abstraction:** Class
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** High
- **CVEs with this as primary weakness:** 23
- **Of those, in CISA KEV:** 1
- **New in 2026:** 6
- **CWE catalog version:** 4.21

## Description

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

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.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Architecture and Design | OMISSION: This weakness is caused by missing a security tactic during the architecture and design phase. |
| Implementation | - |

## Applicable platforms

**Technologies:** Web Server (Often)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Access Control | Bypass Protection Mechanism, Gain Privileges or 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, or 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. |

## Potential mitigations

### 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 (Attack Surface Reduction)

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) \[REF-529\]. Apply this against the state or sensitive data that has to be exposed, which can guarantee the integrity of the data - i.e., that the data has not been modified. Ensure that a strong hash function is used (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 \[REF-1482\].

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.

## Detection methods

### Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Effectiveness: High

### Fuzzing

Use dynamic tools and techniques that interact with the product using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The product's operation may slow down, but it should not become unstable, crash, or generate incorrect results.

### Manual Dynamic Analysis

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.

## Demonstrative examples

### Example 1

In the following example, an authentication flag is read from a browser cookie, thus allowing for external control of user state data.

Bad code:

```java
Cookie[] cookies = request.getCookies();
for (int i =0; i< cookies.length; i++) {
    Cookie c = cookies[i];
    if (c.getName().equals("authenticated") && Boolean.TRUE.equals(c.getValue())) {
        authenticated = true;
    }
}
```

### Example 2

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

Bad code:

```java
String rName = request.getParameter("reportName");
File rFile = new File("/usr/local/apfr/reports/" + rName);
...
rFile.delete();
```

### Example 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.

Bad code:

```java
fis = new FileInputStream(cfg.getProperty("sub")+".txt");
amt = fis.read(arr);
out.println(arr);
```

### Example 4

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.

Bad code:

```c
#define DIR "/restricted/directory"

char cmd[500];
sprintf(cmd, "ls -l %480s", DIR);
/* Raise privileges to those needed for accessing DIR. */

RaisePrivileges(...);
system(cmd);
DropPrivileges(...);
...
```

Attack code:

```
The user sets the PATH to reference a directory under the attacker's control, such as "/my/dir/". The attacker creates a malicious program called "ls", and puts that program in /my/dir The user executes the program. When system() is executed, the shell consults the PATH to find the ls program The program finds the attacker's malicious program, "/my/dir/ls". It doesn't find "/bin/ls" because PATH does not contain "/bin/". The program executes the attacker's malicious program with the raised privileges.
```

### Example 5

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.

Bad code:

```perl
$ENV{"HOMEDIR"} = "/home/mydir/public/";
my $stream = AcceptUntrustedInputStream();
while (<$stream>) {
    chomp;
    if (/^ENV ([\w\_]+) (.*)/) {
        $ENV{$1} = $2;
    }
    elsif (/^QUIT/) { ... }
    elsif (/^LIST/) {
        open($fh, "/bin/ls -l $ENV{HOMEDIR}|");
        while (<$fh>) {
            SendOutput($stream, "FILEINFO: $_");
        }
        close($fh);
    }
}
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2005-2428 | Mail client stores password hashes for unrelated accounts in a hidden form field. |
| CVE-2008-0306 | Privileged program trusts user-specified environment variable to modify critical configuration settings. |
| CVE-1999-0073 | Telnet daemon allows remote clients to specify critical environment variables for the server, leading to code execution. |
| CVE-2007-4432 | Untrusted search path vulnerability through modified LD\_LIBRARY\_PATH environment variable. |
| CVE-2006-7191 | Untrusted search path vulnerability through modified LD\_LIBRARY\_PATH environment variable. |
| CVE-2008-5738 | Calendar application allows bypass of authentication by setting a certain cookie value to 1. |
| CVE-2008-5642 | Setting of a language preference in a cookie enables path traversal attack. |
| CVE-2008-5125 | Application allows admin privileges by setting a cookie value to "admin." |
| CVE-2008-5065 | Application allows admin privileges by setting a cookie value to "admin." |
| CVE-2008-4752 | Application allows admin privileges by setting a cookie value to "admin." |
| CVE-2000-0102 | Shopping cart allows price modification via hidden form field. |
| CVE-2000-0253 | Shopping cart allows price modification via hidden form field. |
| 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. |

## Real CVEs with this weakness (sample of 12 of 23)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-132224 | Optimizely Web Experimentation External Control of Critical State Data Vulnerability | high | 7.1 | - | Yes | 2026-11-18 |
| CVE-2023-0575 | Remote Code Execution | critical | 9.8 | - | No | 2023-02-09 |
| CVE-2020-27872 | NETGEAR R7450 Password Recovery External Control of Critical State Data Authentication Bypass Vulnerability | high | 8.8 | - | No | 2021-02-04 |
| CVE-2026-50053 | Zimbra Collaboration Suite RestFilter Request Attribute Override via Unauthenticated URL Parameters | high | 8.7 | - | No | 2026-10-23 |
| CVE-2018-15382 | Cisco HyperFlex Software Static Signing Key Vulnerability | high | 8.6 | - | No | 2018-10-05 |
| CVE-2024-8754 | External Control of Critical State Data in GitLab | high | 8.1 | - | No | 2024-09-12 |
| CVE-2026-95432 | - | high | 7.8 | - | No | 2026-11-23 |
| CVE-2023-29403 | Unsafe behavior in setuid/setgid binaries in runtime | high | 7.8 | - | No | 2023-06-08 |
| CVE-2018-4180 | macOS High Sierra: CUPS - A local process may modify other processes without entitlement checks | high | 7.8 | - | No | 2019-01-11 |
| CVE-2019-9496 | An invalid authentication sequence could result in the hostapd process terminating due to missing state validation steps | high | 7.5 | - | No | 2019-04-17 |
| CVE-2025-49090 | - | high | 7.1 | - | No | 2025-10-02 |
| CVE-2024-22387 | - | medium | 6.8 | - | No | 2024-07-11 |

## Related attack patterns (CAPEC)

- [CAPEC-21](https://radicalnotion.ai/capec/capec-21): Exploitation of Trusted Identifiers
- [CAPEC-31](https://radicalnotion.ai/capec/capec-31): Accessing/Intercepting/Modifying HTTP Cookies

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-668](https://radicalnotion.ai/cwe/cwe-668) | Exposure of Resource to Wrong Sphere |
| Child | [CWE-15](https://radicalnotion.ai/cwe/cwe-15) | External Control of System or Configuration Setting |
| Child | [CWE-73](https://radicalnotion.ai/cwe/cwe-73) | External Control of File Name or Path |
| Child | [CWE-426](https://radicalnotion.ai/cwe/cwe-426) | Untrusted Search Path |
| Child | [CWE-472](https://radicalnotion.ai/cwe/cwe-472) | External Control of Assumed-Immutable Web Parameter |
| Child | [CWE-565](https://radicalnotion.ai/cwe/cwe-565) | Reliance on Cookies without Validation and Integrity Checking |
| Related | [CWE-352](https://radicalnotion.ai/cwe/cwe-352) | Cross-Site Request Forgery |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| Software Fault Patterns | Exposed Data | SFP23 | - |

## Frequently asked questions

### What is CWE-642?

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

### What CVEs are caused by CWE-642?

23 recorded CVEs are attributed to CWE-642, including CVE-2026-132224, CVE-2023-0575 and CVE-2020-27872. 1 is listed in CISA's Known Exploited Vulnerabilities (KEV) catalog.

### How do you prevent CWE-642?

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.

### How is CWE-642 detected?

Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

### What are the consequences of CWE-642?

Exploiting CWE-642 can lead to: Bypass Protection Mechanism, Gain Privileges or Assume Identity, Read Application Data, DoS: Crash, Exit, or Restart.

### Is CWE-642 actively exploited?

Yes. 1 CWE-642 vulnerability is in CISA's KEV catalog of actively exploited flaws, out of 23 recorded CVEs.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/642.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-642). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
