CWE-312

Cleartext Storage of Sensitive Information. [Information-Management-Errors, Protection-Mechanism-Failure]

Required inputs: IR

The product stores sensitive information in cleartext within a resource that might be accessible to another control sphere.

Because the information is stored in cleartext (i.e., unencrypted), attackers could potentially read it. Even if the information is encoded in a way that is not human-readable, certain techniques could determine which encoding is being used, then decode the information.

When organizations adopt cloud services, it can be easier for attackers to access the data from anywhere on the Internet.

In some systems/environments such as cloud, the use of "double encryption" (at both the software and hardware layer) might be required, and the developer might be solely responsible for both layers, instead of shared responsibility with the administrator of the broader system/environment.

Demonstrative Examples
Example 1

The following code excerpt stores a plaintext user account ID in a browser cookie.

Example Language:Java (Unsupported language for documentation only)
    response.addCookie( new Cookie("userAccountID", acctID);

Because the account ID is in plaintext, the user's account information is exposed if their computer is compromised by an attacker.

Example 2

This code writes a user's login information to a cookie so the user does not have to login again later.

Example Language:PHP (Unsupported language for documentation only)
    function persistLogin($username, $password){
        $data = array("username" => $username, "password"=> $password);
        setcookie ("userdata", $data);
    }

The code stores the user's username and password in plaintext in a cookie on the user's machine. This exposes the user's login information if their computer is compromised by an attacker. Even if the user's machine is not compromised, this weakness combined with cross-site scripting (CWE-79) could allow an attacker to remotely copy the cookie.

Also note this example code also exhibits Plaintext Storage in a Cookie (CWE-315).

Example 3

The following code attempts to establish a connection, read in a password, then store it to a buffer.

Example Language:C
    server.sin_family = AF_INET; hp = gethostbyname(argv[1]);
    if (hp==NULL) error("Unknown host");
    memcpy( (char *)&server.sin_addr,(char *)hp->h_addr,hp->h_length);
    if (argc < 3) port = 80;
    else port = (unsigned short)atoi(argv[3]);
    server.sin_port = htons(port);
    if (connect(sock, (struct sockaddr *)&server, sizeof server) < 0) error("Connecting");
    ...
    while ((n=read(sock,buffer,BUFSIZE-1))!=-1) {
        write(dfd,password_buffer,n);
        ...

While successful, the program does not encrypt the data before writing it to a buffer, possibly exposing it to unauthorized actors.

Example 4

The following examples show a portion of properties and configuration files for Java and ASP.NET applications. The files include username and password information but they are stored in cleartext.

This Java example shows a properties file with a cleartext username / password pair.

Example Language:Java (Unsupported language for documentation only)
    # Java Web App ResourceBundle properties file
    ...
    webapp.ldap.username=secretUsername
    webapp.ldap.password=secretPassword
    ...

The following example shows a portion of a configuration file for an ASP.Net application. This configuration file includes username and password information for a connection to a database but the pair is stored in cleartext.

Example Language:ASP.NET (Unsupported language for documentation only)
    ...
    <connectionStrings>
        <add name="ud_DEV" connectionString="connectDB=uDB; uid=db2admin; pwd=password; dbalias=uDB;" providerName="System.Data.Odbc" />
    </connectionStrings>
    ...

Username and password information should not be included in a configuration file or a properties file in cleartext as this will allow anyone who can read the file access to the resource. If possible, encrypt this information.

Example 5

In 2022, the OT:ICEFALL study examined products by 10 different Operational Technology (OT) vendors. The researchers reported 56 vulnerabilities and said that the products were "insecure by design" [REF-1283]. If exploited, these vulnerabilities often allowed adversaries to change how the products operated, ranging from denial of service to changing the code that the products executed. Since these products were often used in industries such as power, electrical, water, and others, there could even be safety implications.

At least one OT product stored a password in plaintext.

Example 6

In 2021, a web site operated by PeopleGIS stored data of US municipalities in Amazon Web Service (AWS) Simple Storage Service (S3) buckets.

Example Language:Other (Unsupported language for documentation only)
    A security researcher found 86 S3 buckets that could be accessed without authentication (CWE-306) and stored data unencrypted (CWE-312). These buckets exposed over 1000 GB of data and 1.6 million files including physical addresses, phone numbers, tax documents, pictures of driver's license IDs, etc. [REF-1296] [REF-1295]

While it was not publicly disclosed how the data was protected after discovery, multiple options could have been considered.

Example Language:Other (Unsupported language for documentation only)
    The sensitive information could have been protected by ensuring that the buckets did not have public read access, e.g., by enabling the s3-account-level-public-access-blocks-periodic rule to Block Public Access. In addition, the data could have been encrypted at rest using the appropriate S3 settings, e.g., by enabling server-side encryption using the s3-bucket-server-side-encryption-enabled setting. Other settings are available to further prevent bucket data from being leaked. [REF-1297]
Example 7

Consider the following PowerShell command examples for encryption scopes of Azure storage objects. In the first example, an encryption scope is set for the storage account.

Example Language:Shell (Unsupported language for documentation only)
    New-AzStorageEncryptionScope -ResourceGroupName "MyResourceGroup" -AccountName "MyStorageAccount" -EncryptionScopeName testscope -StorageEncryption

The result (edited and formatted for readability) might be:

Example Language:Other (Unsupported language for documentation only)
    ResourceGroupName: MyResourceGroup, StorageAccountName: MyStorageAccount

    Name
                           State
                           Source
                           RequireInfrastructureEncryption


                           testscope
                           Enabled
                           Microsoft.Storage

However, the empty string under RequireInfrastructureEncryption indicates this service was not enabled at the time of creation, because the -RequireInfrastructureEncryption argument was not specified in the command.

Including the -RequireInfrastructureEncryption argument addresses the issue:

Example Language:Shell (Unsupported language for documentation only)
    New-AzStorageEncryptionScope -ResourceGroupName "MyResourceGroup" -AccountName "MyStorageAccount" -EncryptionScopeName testscope -StorageEncryption -RequireInfrastructureEncryption

This produces the report:

(result)
    Example Language:Other
    ResourceGroupName: MyResourceGroup, StorageAccountName: MyStorageAccount

    Name
                           State
                           Source
                           RequireInfrastructureEncryption


                           testscope
                           Enabled
                           Microsoft.Keyvault
                           True

In a scenario where both software and hardware layer encryption is required ("double encryption"), Azure's infrastructure encryption setting can be enabled via the CLI or Portal. An important note is that infrastructure hardware encryption cannot be enabled or disabled after a blob is created. Furthermore, the default value for infrastructure encryption is disabled in blob creations.

Excerpts from CWE [https://cwe.mitre.org], Copyright (C) 2006-2026, the MITRE Corporation. See 9.4 3rd-Party Licenses in the documentation for full details.

Possible Messages

Key

Text

Severity

Disabled

unprotected_payload

Data is stored without prior encryption or authentication.

None

False

Options

critical_routines_pattern

critical_routines_pattern : typing.Pattern[str] = 'authenticate'

Routines with a fully qualified name matching this pattern are considered as taking credentials for parameters
 

key_detection_pattern

key_detection_pattern : typing.Pattern[str] = 'BEGIN (.*) PRIVATE KEY'

Regex pattern used to detect the ASCII armor of private keys in string literals
 

payload_parameters

payload_parameters

Type: dict[bauhaus.analysis.config.FunctionName, set[int]]

Default:

{
   'fputs': {0},
   'fwrite': {0},
   'pwrite': {1},
   'write': {1}
}
Sinks that are only reported when their payload is additionally named like sensitive data, i.e. matches suspect_detection_pattern. Maps a function name to the positions of its data-carrying parameters.
 

protection_functions

protection_functions

Type: list[bauhaus.analysis.config.QualifiedName]

Default: ['EVP_EncryptUpdate', 'EVP_EncryptFinal_ex', 'EVP_CipherUpdate', 'mbedtls_cipher_update', 'mbedtls_aes_crypt_cbc', 'wc_AesCbcEncrypt', 'Csm_Encrypt', 'CryIf_ProcessJob', 'Crypto_ProcessJob', 'HMAC', 'EVP_DigestSignFinal', 'mbedtls_md_hmac_finish', 'wc_CmacFinal', 'Csm_MacGenerate']

Functions that render a payload acceptable to transmit or store. Integrity mechanisms are accepted alongside encryption, because coding standards covering vehicle buses treat an authenticated message as adequately protected. Delete the MAC/signature entries to read this rule strictly as a confidentiality check.
 

sensitive_payload_functions

sensitive_payload_functions : set[bauhaus.analysis.config.QualifiedName] = set()

Sinks whose payload is sensitive by virtue of the sink itself, and whose calls are therefore reported whenever no protecting call precedes them.
 

suspect_detection_pattern

suspect_detection_pattern : typing.Pattern[str] = 'password'

Objects with identifiers including the pattern are considered suspects for holding credentials