CWE-311¶
Missing Encryption of Sensitive Data. [Protection-Mechanism-Failure]
Required inputs: IR
| The product does not encrypt sensitive or critical information before storage or transmission. |
Demonstrative Examples
Example 1
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 2
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 3
The following code attempts to establish a connection to a site to communicate sensitive information.
Example Language:Java (Unsupported language for documentation only)
try {
URL u = new URL("http://www.secret.example.org/");
HttpURLConnection hu = (HttpURLConnection) u.openConnection();
hu.setRequestMethod("PUT");
hu.connect();
OutputStream os = hu.getOutputStream();
hu.disconnect();
}
catch (IOException e) {
//...
}
Though a connection is successfully made, the connection is unencrypted and it is possible that all sensitive data sent to or received from the server will be read by unintended actors.
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 leaves the program without prior encryption or authentication. |
None |
False |
Options¶
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
critical_routines_pattern¶
critical_routines_pattern : typing.Pattern[str] = 'authenticate'
key_detection_pattern¶
key_detection_pattern : typing.Pattern[str] = 'BEGIN (.*) PRIVATE KEY'
payload_parameters¶
payload_parameters
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.Type: dict[bauhaus.analysis.config.FunctionName, set[int]]
Default:
{ 'fputs': {0}, 'fwrite': {0}, 'pwrite': {1}, 'send': {1}, 'sendmsg': {1}, 'sendto': {1}, 'write': {1} }
protection_functions¶
protection_functions
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.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']
sensitive_payload_functions¶
sensitive_payload_functions : set[bauhaus.analysis.config.QualifiedName] = {'CanIf_Transmit', 'Com_SendSignal', 'PduR_ComTransmit', 'SoAd_IfTransmit'}
suspect_detection_pattern¶
suspect_detection_pattern : typing.Pattern[str] = 'password'