Security: Fix CWE-328 (Weak Hash Algorithm) vulnerability in src/main/java/org/owasp/benchmark/testcode/BenchmarkTest01761.java:50#670
Open
appsecai-app[bot] wants to merge 1 commit intomainfrom
Conversation
…nerability
Replace MessageDigest.getInstance("SHA1") with SHA-256 in
BenchmarkTest01761.java:50. SHA1 is cryptographically broken and
vulnerable to practical collision attacks. SHA-256 provides collision
resistance and is available in the standard SUN JCA provider.
Fixes 1 CWE-328 vulnerability.
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
69c734eb82da7093ceeca616src/main/java/org/owasp/benchmark/testcode/BenchmarkTest01761.java:50Description: The code instantiates a MessageDigest using the SHA1 algorithm via
MessageDigest.getInstance("SHA1", "SUN")at line 50. SHA1 is cryptographically broken and unsuitable for any security-sensitive hash application. Practical collision attacks have been demonstrated (SHAttered, 2017), meaning two different inputs can produce the same hash value.Why this matters
Attack scenario: An attacker can exploit SHA1's collision vulnerability to forge credentials or bypass integrity checks. Since the hash is written to
passwordFile.txt(lines 68-78), the collision weakness directly compromises password storage security. An attacker could craft two different passwords that produce the same SHA1 hash, allowing unauthorized access.Risk level: Medium - SHA1 collision attacks are practical and well-documented. Any system relying on SHA1 for credential integrity or data fingerprinting is vulnerable to collision-based forgery.
Why we're changing it
Vulnerability confirmed:
java.security.MessageDigest.getInstance("SHA1", "SUN")— direct instantiation of broken SHA1 algorithmparam = scr.getTheValue("BenchmarkTest01761")— attacker-controlled HTTP request parameter flows into the hash operationmd.update(input)passwordFile.txt— credential storage context confirms security-sensitive useRoot cause: SHA1 produces only 160-bit output and is not collision-resistant. The SHAttered attack (2017) demonstrated real-world collisions, proving SHA1 is unsuitable for any cryptographic integrity or signature purpose.
How we confirmed
doSomething()method tomd.update()callpasswordFile.txt, indicating credential/password storage contextVulnerability 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 Parameter<br/>BenchmarkTest01761"] --> B["User Input Flows to<br/>MessageDigest.getInstance('SHA1')"] B --> C["❌ SHA1 Hash Computed<br/>(Collision-Vulnerable)"] C --> D["Hash Written to<br/>passwordFile.txt"] D --> E["⚠️ Credential Forgery Risk<br/>Attacker Crafts Colliding Password"] F["✅ Fixed - SHA-256 Algorithm"] --> G["SHA-256 Hash Computed<br/>(Collision-Resistant)"] G --> H["Hash Written to<br/>passwordFile.txt"] H --> I["🛡️ Collision Attack Blocked"] style C fill:#FFE5E5,stroke:#F65A5A style E fill:#FEF3C7,stroke:#F59E0B style F fill:#DCFCE7,stroke:#16A34A style G fill:#DCFCE7,stroke:#16A34A style I fill:#DCFCE7,stroke:#16A34ARunnable Verification Script (click to expand)
Save this script and run with
bash verify_fix.sh:Vulnerable flow: src/main/java/org/owasp/benchmark/testcode/BenchmarkTest01761.java:50
Weak Hash 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"] direction LR A1["Project"] --> A2["Reversible one-way hash used"] A2 --> A3["💥 Password Recovery"] end Vulnerable ~~~ Fixed subgraph Fixed["✅ Fixed Flow"] direction LR B1["Project"] --> B2["Use bcrypt/argon2 for passwords"] B3["🛡️ Attack Blocked"] B2 --> B3 end style A2 fill:#FFE5E5,color:#000 style A3 fill:#ffa94d,color:#000 style B2 fill:#74c0fc,color:#000 style B3 fill:#DCFCE7,color:#000How we fixed it
Change made: Replaced
MessageDigest.getInstance("SHA1", "SUN")withMessageDigest.getInstance("SHA-256", "SUN")at line 50.Why SHA-256:
Alternatives considered:
Vulnerabilities Addressed
CWE-328
Use Of Sha1
How we validated it
How to verify
getInstance("SHA-256", "SUN")and no SHA1 references remaingrep -n "SHA-256" src/main/java/org/owasp/benchmark/testcode/BenchmarkTest01761.javato confirm the fixBefore you merge
Learn more
This fix was generated by AppSecAI. Please review before merging.