CWE-311: Missing Encryption of Sensitive Data

Description:
The product does not encrypt sensitive or critical information before storage or transmission.

Affected languages: Not Language-Specific
Parent weaknesses: CWE-693

Consequences:
  - Confidentiality: Read Application Data
  - Confidentiality: Modify Application Data

Detection methods:
  - Manual Analysis: The characterizaton of sensitive data often requires domain-specific understanding, so manual methods are useful. However, manual efforts might not achieve desired code coverage within limited time co
  - Automated Analysis: Automated measurement of the entropy of an input/output source may indicate the use or lack of encryption, but human analysis is still required to distinguish intentionally-unencrypted data (e.g. meta
  - Manual Static Analysis - Binary or Bytecode: According to SOAR [REF-1479], the following detection techniques may be useful: 
                   
                      Cost effective for partial coverage: 
                         
             
  - Dynamic Analysis with Automated Results Interpretation: According to SOAR [REF-1479], the following detection techniques may be useful: 
                   
                      Cost effective for partial coverage: 
                         
             

Mitigations:
  - [Requirements] Clearly specify which data or resources are valuable enough that they should be protected by encryption. Require that any transmission or storage of this data/resource should use well-vetted encryption algorithms.
  - [Architecture and Design] Ensure that encryption is properly integrated into the system design, including but not necessarily limited to: 
                      
                         Encryption that is needed to store or transmit private data of the users of the system 
                         Encryption that is needed 
  - [Architecture and Design] When there is a need to store or transmit sensitive data, use strong, up-to-date cryptographic algorithms to encrypt that data. Select a well-vetted algorithm that is currently considered to be strong by experts in the field, and use well-tested implementations. As with all cryptographic mechanisms,
  - [Architecture and Design] 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 compartm

Demonstrative examples:
This code writes a user's login information to a cookie so the user does not have to login again later.
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.
function persistLogin($username, $password){ $data = array("username" => $username, "password"=> $password); setcookie ("userdata", $data); }

The following code attempts to establish a connection, read in a password, then store it to a buffer.
While successful, the program does not encrypt the data before writing it to a buffer, possibly exposing it to unauthorized actors.
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); ...

Real-world examples:
  - CVE-2022-26390: wireless battery product stores credentials and Personal Health Information (PHI) without encryption
  - CVE-2009-2272: password and username stored in cleartext in a cookie
  - CVE-2009-1466: password stored in cleartext in a file with insecure permissions
  - CVE-2009-0152: chat program disables SSL in some circumstances even when the user says to use SSL.
  - CVE-2009-1603: Chain: product uses an incorrect public exponent when generating an RSA key, which effectively disables the encryption