What it is: PHP External Variable Modification (CWE-473) is a security weakness where variables in a PHP application are improperly modified by external sources, such as query parameters or cookies.
Why it matters: It exposes the application to integrity risks and unauthorized data modification. Proper validation of external inputs can mitigate this risk.
How to fix it: Disable register_globals and validate all input from external sources before use.
TL;DR: PHP External Variable Modification (CWE-473) is a security vulnerability where variables in a PHP application can be improperly modified by external inputs, leading to integrity risks. Proper validation of these inputs prevents unauthorized data modification.
| Field | Value |
|---|---|
| CWE ID | CWE-473 |
| OWASP Category | Not directly mapped |
| CAPEC | CAPEC-77 |
| Typical Severity | Critical |
| Affected Technologies | PHP, web applications |
| Detection Difficulty | Moderate |
| Last Updated | 2026-07-29 |
What is PHP External Variable Modification?
PHP External Variable Modification (CWE-473) is a type of security vulnerability that occurs when variables in a PHP application are improperly modified by external sources, such as query parameters or cookies. As defined by the MITRE Corporation under CWE-473, this weakness can expose an application to integrity risks and unauthorized data modification.
Quick Summary
PHP External Variable Modification allows attackers to manipulate variables within a PHP application through external inputs like query strings or cookies. This can lead to unauthorized access and manipulation of sensitive data. Proper validation and sanitization of these inputs are crucial for preventing such vulnerabilities.
Jump to: Quick Summary · PHP External Variable Modification Overview · How PHP External Variable Modification Works · Business Impact of PHP External Variable Modification · PHP External Variable Modification Attack Scenario · How to Detect PHP External Variable Modification · How to Fix PHP External Variable Modification · Framework-Specific Fixes for PHP External Variable Modification · How to Ask AI to Check Your Code for PHP External Variable Modification · PHP External Variable Modification Best Practices Checklist · PHP External Variable Modification FAQ · Vulnerabilities Related to PHP External Variable Modification · References · Scan Your Own Site
PHP External Variable Modification Overview
What
PHP External Variable Modification occurs when a PHP application improperly modifies variables based on external input sources like query parameters or cookies.
Why it matters
This vulnerability exposes the application to integrity risks and unauthorized data modification, leading to potential security breaches.
Where it occurs
It typically happens in web applications that rely heavily on user inputs without proper validation mechanisms.
Who is affected
Web developers and administrators who manage PHP-based web applications are at risk if they do not properly validate external inputs.
Who is NOT affected
Applications that enforce strict input validation and avoid using features like register_globals are less susceptible to this vulnerability.
How PHP External Variable Modification Works
Root Cause
The root cause lies in the lack of proper validation for variables derived from external sources, allowing unauthorized modification of application state.
Attack Flow
- An attacker sends a request with maliciously crafted query parameters or cookies.
- The PHP application processes these inputs without adequate checks.
- The modified variables lead to unintended behavior within the application.
Prerequisites to Exploit
- External input must be able to modify internal variables directly.
- Application should not validate or sanitize external inputs properly.
Vulnerable Code
<?php
$variable = $_GET['param'];
?>
This code is vulnerable because it assigns an external variable ($_GET['param']) directly without validation, allowing potential manipulation of the application state.
Secure Code
<?php
if (isset($_GET['param'])) {
$variable = filter_var($_GET['param'], FILTER_SANITIZE_STRING);
}
?>
This code is secure because it validates and sanitizes external input before assigning it to a variable, mitigating unauthorized modifications.
Business Impact of PHP External Variable Modification
Integrity
Data integrity can be compromised if variables are modified without proper checks. Sensitive data may be altered or accessed improperly.
Availability
In extreme cases, improper modification of critical application state can lead to denial of service conditions.
Financial and Compliance Consequences
Unauthorized access and manipulation of sensitive data can result in financial losses and non-compliance with regulatory requirements.
PHP External Variable Modification Attack Scenario
- An attacker crafts a request with malicious query parameters.
- The PHP application processes the input without validation.
- Critical variables are modified, leading to unintended behavior or data leakage.
- The attacker exploits this vulnerability for unauthorized access or modification of sensitive information.
How to Detect PHP External Variable Modification
Manual Testing
- Check if external inputs like $_GET and $_POST are used directly in variable assignments.
- Ensure proper validation mechanisms are in place before assigning values from these sources.
Automated Scanners (SAST / DAST)
Static analysis can detect direct assignment of superglobals without validation. Dynamic testing is needed to confirm actual vulnerabilities in a running application.
PenScan Detection
PenScan’s scanner engines like ZAP and Wapiti actively look for instances where external inputs are improperly handled, flagging potential PHP External Variable Modification issues.
False Positive Guidance
A false positive may occur if an input validation mechanism exists but is not detected by the static analysis tool. Review context to ensure proper handling of external variables.
How to Fix PHP External Variable Modification
- Disable register_globals in PHP configuration.
- Validate all external inputs before using them in variable assignments.
- Use strict variable naming conventions that indicate their origin and trust level.
Framework-Specific Fixes for PHP External Variable Modification
<?php
if (isset($_GET['param'])) {
$variable = filter_var($_GET['param'], FILTER_SANITIZE_STRING);
}
?>
This fix demonstrates the use of filter_var to sanitize external input before assignment, ensuring that only safe values are used.
How to Ask AI to Check Your Code for PHP External Variable Modification
Review the following [language] code block for potential CWE-473 PHP External Variable Modification vulnerabilities and rewrite it using strict input validation: [paste code here]
PHP External Variable Modification Best Practices Checklist
✅ Disable register_globals in your PHP configuration. ✅ Validate all external inputs before assigning them to variables. ✅ Use strict variable naming conventions that indicate their origin and trust level.
PHP External Variable Modification FAQ
How does PHP External Variable Modification occur?
It occurs when a PHP application allows external sources like query parameters or cookies to modify variables without proper checks, leading to data integrity issues.
What are the potential consequences of this vulnerability?
This can lead to unauthorized access and modification of sensitive data within the application.
How does one detect PHP External Variable Modification in a codebase?
Detect it by reviewing how variables from external sources are handled and ensuring there is proper validation and sanitization.
What steps should be taken to prevent this vulnerability?
Disable register_globals, validate all input from external sources, and use strict variable naming conventions that indicate their origin.
Can you provide an example of vulnerable code for PHP External Variable Modification?
Example includes directly assigning $_GET or $_POST values to variables without validation.
How does the PenScan platform help in detecting this vulnerability?
PenScan uses advanced static and dynamic analysis techniques to identify potential instances of external variable modification.
What are some best practices for preventing PHP External Variable Modification?
Use strict input validation, avoid using register_globals, and implement a secure coding standard that discourages direct assignment from superglobals.
Vulnerabilities Related to PHP External Variable Modification
| CWE | Name | Relationship |
|---|---|---|
| 471 | Modification of Assumed-Immutable Data (MAID) | ChildOf |
| 98 | Improper Control of Filename for Include/Require Statement in PHP Program (‘PHP Remote File Inclusion’) | CanPrecede |
References
Scan Your Own Site
Manual code review catches what you know to look for. An automated scan catches what you didn’t. Scan your own website using PenScan to find PHP External Variable Modification and other risks before an attacker does.