508
Phase: Architecture and Design
Strategy = Separation of Privilege
Compartmentalize the system to have "safe" areas where trust boundaries can be
unambiguously drawn. Do not allow sensitive data to go outside of the trust boundary and always
be careful when interfacing with a compartment outside of the safe area. Ensure that appropriate
compartmentalization is built into the system design, and the compartmentalization allows for and
reinforces privilege separation functionality. Architects and designers should rely on the principle
of least privilege to decide the appropriate time to use privileges and the time to drop privileges.
Demonstrative Examples
Example 1:
The following code checks validity of the supplied username and password and notifies the user of
a successful or failed login.
Example Language: Perl (Bad)
my $username=param('username');
my $password=param('password');
if (IsValidUsername($username) == 1)
{
if (IsValidPassword($username, $password) == 1)
{
print "Login Successful";
}
else
{
print "Login Failed - incorrect password";
}
}
else
{
print "Login Failed - unknown username";
}
In the above code, there are different messages for when an incorrect username is supplied,
versus when the username is correct but the password is wrong. This difference enables a
potential attacker to understand the state of the login function, and could allow an attacker
to discover a valid username by trying different values until the incorrect password message
is returned. In essence, this makes it easier for an attacker to obtain half of the necessary
authentication credentials.
While this type of information may be helpful to a user, it is also useful to a potential attacker. In the
above example, the message for both failed cases should be the same, such as:
Example Language: (Result)
"Login Failed - incorrect username or password"
Example 2:
This code tries to open a database connection, and prints any exceptions that occur.
Example Language: PHP (Bad)
try {
openDbConnection();
}
//print exception message that includes exception message and configuration file location
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), '\n';
echo 'Check credentials in config file at: ', $Mysql_config_location, '\n';
CWE Version 4.14
CWE-200: Exposure of Sensitive Information to an Unauthorized Actor
CWE-200: Exposure of Sensitive Information to an Unauthorized Actor