A04—Cryptographic Failures
>Control Description
>Prevention & Mitigation Strategies
- 1.Classify and label data processed, stored, or transmitted by an application. Identify which data is sensitive according to privacy laws, regulatory requirements, or business needs.
- 2.Store your most sensitive keys in a hardware or cloud-based HSM.
- 3.Use well-trusted implementations of cryptographic algorithms whenever possible.
- 4.Don't store sensitive data unnecessarily. Discard it as soon as possible or use PCI DSS compliant tokenization or even truncation. Data that is not retained cannot be stolen.
- 5.Make sure to encrypt all sensitive data at rest.
- 6.Ensure up-to-date and strong standard algorithms, protocols, and keys are in place; use proper key management.
- 7.Encrypt all data in transit with protocols >= TLS 1.2 only, with forward secrecy (FS) ciphers, drop support for cipher block chaining (CBC) ciphers, support quantum key change algorithms. For HTTPS enforce encryption using HTTP Strict Transport Security (HSTS). Check everything with a tool.
- 8.Disable caching for responses that contain sensitive data. This includes caching in your CDN, web server, and any application caching (eg: Redis).
- 9.Apply required security controls as per the data classification.
- 10.Do not use unencrypted protocols such as FTP, and STARTTLS. Avoid using SMTP for transmitting confidential data.
- 11.Store passwords using strong adaptive and salted hashing functions with a work factor (delay factor), such as Argon2, yescrypt, scrypt or PBKDF2-HMAC-SHA-512. For legacy systems using bcrypt, get more advice at [OWASP Cheat Sheet: Password Storage](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html)
- 12.Initialization vectors must be chosen appropriate for the mode of operation. This could mean using a CSPRNG (cryptographically secure pseudo random number generator). For modes that require a nonce, the initialization vector (IV) does not need a CSPRNG. In all cases, the IV should never be used twice for a fixed key.
- 13.Always use authenticated encryption instead of just encryption.
- 14.Keys should be generated cryptographically randomly and stored in memory as byte arrays. If a password is used, then it must be converted to a key via an appropriate password base key derivation function.
- 15.Ensure that cryptographic randomness is used where appropriate and that it has not been seeded in a predictable way or with low entropy. Most modern APIs do not require the developer to seed the CSPRNG to be secure.
- 16.Avoid deprecated cryptographic functions, block building methods and padding schemes, such as MD5, SHA1, Cipher Block Chaining Mode (CBC), PKCS number 1 v1.5.
- 17.Ensure settings and configurations meet security requirements by having them reviewed by security specialists, tools designed for this purpose, or both.
- 18.You need to prepare now for post quantum cryptography (PQC), see reference (ENISA) so that high risk systems are safe no later than the end of 2030.
>Attack Scenarios
A site doesn't use or enforce TLS for all pages or supports weak encryption. An attacker monitors network traffic (e.g., at an insecure wireless network), downgrades connections from HTTPS to HTTP, intercepts requests, and steals the user's session cookie. The attacker then replays this cookie and hijacks the user's (authenticated) session, accessing or modifying the user's private data. Instead of the above they could alter all transported data, e.g., the recipient of a money transfer.
The password database uses unsalted or simple hashes to store everyone's passwords. A file upload flaw allows an attacker to retrieve the password database. All the unsalted hashes can be exposed with a rainbow table of pre-calculated hashes. Hashes generated by simple or fast hash functions may be cracked by GPUs, even if they were salted.
>Related CWEs
>References
- •OWASP Proactive Controls: C2: Use Cryptography to Protect Data
- •OWASP Application Security Verification Standard (ASVS)
- •OWASP ASVS V11: Cryptography
- •OWASP ASVS V12: Secure Communication
- •OWASP ASVS V14: Data Protection
- •OWASP Cheat Sheet: Transport Layer Protection
- •OWASP Cheat Sheet: User Privacy Protection
- •OWASP Cheat Sheet: Password Storage
- •OWASP Cheat Sheet: Cryptographic Storage
- •OWASP Cheat Sheet: HSTS
- •OWASP Testing Guide: Testing for weak cryptography
- •ENISA: A Coordinated Implementation Roadmap for the Transition to Post-Quantum Cryptography
- •NIST Releases First 3 Finalized Post-Quantum Encryption Standards
Ask AI
Configure your API key to use AI features.