Security: Fix 2 CWE-326 (Weak Encryption Algorithm) vulnerabilities in src/main/java/org/owasp/benchmark/testcode/BenchmarkTest01740.java:57#657
Open
appsecai-app[bot] wants to merge 1 commit intomainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What we found
69c734eb82da7093ceeca612(DES),69c734eb82da7093ceeca613(DESede)src/main/java/org/owasp/benchmark/testcode/BenchmarkTest01740.java:57Description: The code uses DES (56-bit) and Triple DES (DESede) algorithms for symmetric encryption. Both are cryptographically weak and deprecated by NIST. DES keys are trivially brute-forced with modern hardware in hours. Triple DES retains a 64-bit block size vulnerable to Sweet32 birthday attacks and is deprecated as of 2023.
Why this matters
Risk if not fixed: Encrypted data persisted to disk can be decrypted offline through brute-force attacks. DES key space (2^56 ≈ 72 quadrillion combinations) is exhaustible with commodity hardware in under 24 hours. Triple DES's 64-bit block size enables practical birthday attacks after ~32GB of encrypted data. Attackers gaining file system access can recover plaintext without application compromise.
Risk level: Medium - Should be addressed in regular security maintenance. Escalates to High if encrypted data contains authentication credentials or PII.
Why we're changing it
Root cause analysis:
KeyGenerator.getInstance("DES")— DES is a deprecated 56-bit symmetric cipher, well below the 256-bit minimum recommended by NIST and CWE-326'DESede/ECB/PKCS5Padding'— Triple DES is the subject of the SAST finding and its use is confirmed even absent property overridepasswordFile.txt(lines 80-86), making offline brute-force attack practicalEvidence:
algorithmdefault ='DESede/ECB/PKCS5Padding'— 3DES with ECB mode, no integrityjavax.crypto.Cipher.getInstance(algorithm)— instantiates the weak cipherjavax.crypto.KeyGenerator.getInstance("DES").generateKey()— generates a 56-bit DES key, the weakest possible symmetric keyc.init(ENCRYPT_MODE, key)— weak DES key applied to cipher initialized with 3DES/ECB algorithmHow we confirmed
Vulnerability Flow Diagram
%%{init: {'theme':'base','themeVariables':{'fontFamily':'ui-sans-serif, Inter, system-ui, sans-serif','primaryColor':'#EDE9FE','primaryTextColor':'#1A1A2E','primaryBorderColor':'#7C3AED','lineColor':'#5B21B6','secondaryColor':'#FEF3C7','tertiaryColor':'#DCFCE7'}}}%% flowchart TD A["HTTP Request to BenchmarkTest01740"] --> B["getTheValue() Parameter Extraction"] B --> C["KeyGenerator.getInstance('DES') Line 57"] C --> D["56-bit DES Key Generated"] D --> E["Cipher Algorithm - DESede/ECB/PKCS5Padding Line 53"] E --> F["Encryption Applied to Sensitive Data"] F --> G["Encrypted Output Persisted to passwordFile.txt"] G --> H["❌ Attacker - Brute-force DES keyspace in (24 hours"] H --> I["❌ Plaintext Recovered Offline"] style A fill:#EDE9FE,stroke:#7C3AED style C fill:#FFE5E5,stroke:#F65A5A style D fill:#FFE5E5,stroke:#F65A5A style E fill:#FFE5E5,stroke:#F65A5A style H fill:#FEF3C7,stroke:#F59E0B style I fill:#FEF3C7,stroke:#F59E0BManual Verification Steps
BenchmarkTest01740.javaand confirm line 57 containsKeyGenerator.getInstance("DES")DESedeorDESin the default valueGCMParameterSpecor authenticated encryption mode is present in the original codeKeyGenerator.getInstance("AES")with 256-bit keyAES/GCM/NoPaddingcipher algorithmGCMParameterSpec(128, iv)is passed toc.init()with a 12-byte random IVInvalidAlgorithmParameterExceptionis caught in the exception handlerRunnable Verification Script (click to expand)
Save this script and run with
bash verify_fix.sh:Vulnerable flow: src/main/java/org/owasp/benchmark/testcode/BenchmarkTest01740.java:57
Weak Encryption Algorithm
%%{init: {'theme':'base','themeVariables':{'fontFamily':'ui-sans-serif, Inter, system-ui, sans-serif','primaryColor':'#EDE9FE','primaryTextColor':'#1A1A2E','primaryBorderColor':'#7C3AED','lineColor':'#5B21B6','secondaryColor':'#FEF3C7','tertiaryColor':'#DCFCE7'}}}%% flowchart TD subgraph Vulnerable["❌ Vulnerable Flow - CWE-326 Weak Encryption"] direction LR A1["HTTP Request BenchmarkTest01740"] --> A2["getTheValue() Param Extraction"] A2 --> A3["KeyGenerator getInstance('DES') Line 57"] A3 --> A4["56-bit DES Key Generated"] A4 --> A5["DESede/ECB/PKCS5 Cipher Init Line 53"] A5 --> A6["💥 56-bit Key Brute Forceable in Hours"] end Vulnerable ~~~ Fixed subgraph Fixed["✅ Fixed Flow - AES-GCM Authenticated Encryption"] direction LR B1["HTTP Request BenchmarkTest01740"] --> B2["getTheValue() Param Extraction"] B2 --> B3["KeyGenerator getInstance('AES') Line 57"] B3 --> B4["256-bit AES Key Generated"] B4 --> B5["SecureRandom 12-byte IV GCMParameterSpec(128)"] B5 --> B6["AES/GCM/NoPadding AEAD Cipher Init"] B6 --> B7["🛡️ 256-bit Key Brute Force Infeasible"] end style A3 fill:#FFE5E5,color:#1A1A2E style A4 fill:#FFE5E5,color:#1A1A2E style A5 fill:#FFE5E5,color:#1A1A2E style A6 fill:#ffa94d,color:#000 style B3 fill:#74c0fc,color:#000 style B5 fill:#74c0fc,color:#000 style B6 fill:#74c0fc,color:#000 style B7 fill:#DCFCE7,color:#000How we fixed it
Fix Description
Root cause: The code used DES and Triple DES (DESede) algorithms for symmetric encryption. DES uses a 56-bit key that is trivially brute-forced with modern hardware. Triple DES (3DES/DESede) extends DES to 112/168-bit effective key length but retains the 64-bit block size (vulnerable to Sweet32 birthday attacks at ~32GB of data) and is deprecated by NIST as of 2023. Both algorithms are classified as cryptographically weak under CWE-326 (Inadequate Encryption Strength).
Fix approach: Replaced DES key generation with AES (KeyGenerator.getInstance("AES")), replaced the DESede/ECB/PKCS5Padding default cipher spec with AES/GCM/NoPadding, and added a cryptographically random 12-byte IV with a 128-bit GCM authentication tag via GCMParameterSpec. AES-256 provides 256-bit key strength well above NIST minimum recommendations. GCM mode provides authenticated encryption (AEAD), eliminating padding oracle and bit-flipping attacks that affect CBC/ECB modes. A fresh SecureRandom IV per encryption operation prevents IV reuse vulnerabilities.
Numeric thresholds justified:
Alternatives considered and rejected:
Changes made:
"DESede/ECB/PKCS5Padding"(Triple DES) to"AES/GCM/NoPadding"— eliminates the CWE-326 Triple DES weakness"DES"to"AES"— eliminates the CWE-326 DES weakness. A 12-byte random IV is generated viaSecureRandomand passed toc.init()viaGCMParameterSpec(128, iv)— required for GCM mode initializationjava.security.InvalidAlgorithmParameterExceptionadded — required becausec.init()withGCMParameterSpecdeclares this checked exceptionVulnerabilities Addressed
CWE-326
Desede Is Deprecated
CWE-326
Des Is Deprecated
How we validated it
How to verify
Reviewers can confirm this fix by:
KeyGenerator.getInstance("AES")and line 53 uses"AES/GCM/NoPadding"grep -E '(DES|ECB)' src/main/java/org/owasp/benchmark/testcode/BenchmarkTest01740.java— should return no matchesSecureRandomis used to generate a 12-byte IV before each encryptionInvalidAlgorithmParameterExceptionis caught in the try-catch blockBefore you merge
InvalidAlgorithmParameterExceptionadded)Learn more
This fix was generated by AppSecAI. Please review before merging.