1975
This code attempts to login a user using credentials from a POST request:
Example Language: PHP (Bad)
// $user and $pass automatically set from POST request
if (login_user($user,$pass)) {
$authorized = true;
}
...
if ($authorized) {
generatePage();
}
Because the $authorized variable is never initialized, PHP will automatically set $authorized to any
value included in the POST request if register_globals is enabled. An attacker can send a POST
request with an unexpected third value 'authorized' set to 'true' and gain authorized status without
supplying valid credentials.
Here is a fixed version:
Example Language: PHP (Good)
$user = $_POST['user'];
$pass = $_POST['pass'];
$authorized = false;
if (login_user($user,$pass)) {
$authorized = true;
}
...
This code avoids the issue by initializing the $authorized variable to false and explicitly retrieving
the login credentials from the $_POST variable. Regardless, register_globals should never be
enabled and is disabled by default in current versions of PHP.
Observed Examples
Reference Description
CVE-2022-36349 insecure default variable initialization in BIOS firmware for a hardware board
allows DoS
https://www.cve.org/CVERecord?id=CVE-2022-36349
CVE-2022-42467 A generic database browser interface has a default mode that exposes a web
server to the network, allowing queries to the database.
https://www.cve.org/CVERecord?id=CVE-2022-42467
MemberOf Relationships
This MemberOf relationships table shows additional CWE Catgeories and Views that reference this
weakness as a member. This information is often useful in understanding where a weakness fits
within the context of external information sources.
Nature Type ID Name Page
MemberOf 1416 Comprehensive Categorization: Resource Lifecycle
Management
1400 2545
Notes
Maintenance
This entry improves organization of concepts under initialization. The typical CWE model is to
cover "Missing" and "Incorrect" behaviors. Arguably, this entry could be named as "Incorrect"
instead of "Insecure." This might be changed in the near future.
Related Attack Patterns
CWE Version 4.14
CWE-1189: Improper Isolation of Shared Resources on System-on-a-Chip (SoC)
CWE-1189: Improper Isolation of Shared Resources on System-on-a-Chip (SoC)