CWE-285: Improper Authorization
Description
The product does not perform or incorrectly performs an authorization check when an actor attempts to access a resource or perform an action.
Submission Date :
July 19, 2006, midnight
Modification Date :
2023-06-29 00:00:00+00:00
Organization :
MITRE
Extended Description
Assuming a user with a given identity, authorization is the process of determining whether that user can access a given resource, based on the user's privileges and any permissions or other access-control specifications that apply to the resource.
When access control checks are not applied consistently - or not at all - users are able to access data or perform actions that they should not be allowed to perform. This can lead to a wide range of problems, including information exposures, denial of service, and arbitrary code execution.
Example - 1
This function runs an arbitrary SQL query on a given database, returning the result of the query. While this code is careful to avoid SQL Injection, the function does not confirm the user sending the query is authorized to do so. An attacker may be able to obtain sensitive employee information from the database.
// //Use a prepared statement to avoid CWE-89//
mysql_select_db($dbName,$globalDbHandle) or die("Could not open Database".$dbName);$preparedStatement = $globalDbHandle->prepare('SELECT * FROM employees WHERE name = :name');$preparedStatement->execute(array(':name' => $name));return $preparedStatement->fetchAll();
// /...///
function runEmployeeQuery($dbName, $name){}$employeeRecord = runEmployeeQuery('EmployeeDB',$_GET['EmployeeName']);
Example - 2
The following program could be part of a bulletin board system that allows users to send private messages to each other. This program intends to authenticate the user before deciding whether a private message should be displayed. Assume that LookupMessageObject() ensures that the $id argument is numeric, constructs a filename based on that id, and reads the message details from that file. Also assume that the program stores all private messages for all users in the same directory. While the program properly exits if authentication fails, it does not ensure that the message is addressed to the user. As a result, an authenticated attacker could provide any arbitrary identifier and read private messages that were intended for other users. One way to avoid this problem would be to ensure that the "to" field in the message object matches the username of the authenticated user.
my($id) = @_;my $Message = LookupMessageObject($id);print "From: " . encodeHTML($Message->{from}) . "<br>\n";print "Subject: " . encodeHTML($Message->{subject}) . "\n";print "<hr>\n";print "Body: " . encodeHTML($Message->{body}) . "\n";
// # For purposes of this example, assume that CWE-309 and//
// # CWE-523 do not apply.//
ExitError("invalid username or password");
sub DisplayPrivateMessage {}my $q = new CGI;if (! AuthenticateUser($q->param('username'), $q->param('password'))) {}my $id = $q->param('id');DisplayPrivateMessage($id);
Related Weaknesses
This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined to give an overview of the different insight to similar items that may exist at higher and lower levels of abstraction.
CWE-284: Improper Access Control
CWE-552: Files or Directories Accessible to External Parties
CWE-732: Incorrect Permission Assignment for Critical Resource
CWE-862: Missing Authorization
CWE-863: Incorrect Authorization
CWE-926: Improper Export of Android Application Components
CWE-927: Use of Implicit Intent for Sensitive Communication
CWE-1230: Exposure of Sensitive Information Through Metadata
CWE-1256: Improper Restriction of Software Interfaces to Hardware Features
CWE-1297: Unprotected Confidential Information on Device is Accessible by OSAT Vendors
CWE-1328: Security Version Number Mutable to Older Versions
Visit http://cwe.mitre.org/ for more details.