Java: treat hash/encrypt/digest methods as sensitive-log sanitizers#21654
Open
MarkLee131 wants to merge 1 commit intogithub:mainfrom
Open
Java: treat hash/encrypt/digest methods as sensitive-log sanitizers#21654MarkLee131 wants to merge 1 commit intogithub:mainfrom
MarkLee131 wants to merge 1 commit intogithub:mainfrom
Conversation
The sensitive-log query (CWE-532) lacked sanitizers for hashed or encrypted data, while the sibling cleartext-storage query (CWE-312) already recognized methods with "encrypt", "hash", or "digest" in their names as sanitizers (CleartextStorageQuery.qll:86). This adds an EncryptionBarrier to SensitiveLoggingQuery that applies the same name-based heuristic, making the two queries consistent. Calls like DigestUtils.sha256Hex(password) or hashPassword(secret) are no longer flagged when their results are logged.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Java CWE-532 sensitive logging query to treat hashed/encrypted/digested values as sanitized (using the same name-based heuristic already used by the sibling CWE-312 cleartext storage query), reducing false positives when only derived values are logged.
Changes:
- Add an
EncryptionBarrierto thejava/sensitive-logquery to stop flows through method calls whose names containencrypt,hash, ordigest. - Extend the CWE-532 query test to cover hash/digest/encrypt cases and update the expected results accordingly.
- Add a change note documenting the analysis change.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| java/ql/lib/semmle/code/java/security/SensitiveLoggingQuery.qll | Adds a new barrier class to treat hash/encrypt/digest-named method calls as sanitizers for sensitive-log taint tracking. |
| java/ql/test/query-tests/security/CWE-532/Test.java | Adds new test cases ensuring hashed/digested/encrypted values are not flagged when logged. |
| java/ql/test/query-tests/security/CWE-532/SensitiveLogInfo.expected | Updates expected results to include the new alert and preserve “safe” outcomes for sanitized flows. |
| java/ql/lib/change-notes/2026-04-04-sensitive-log-hash-sanitizer.md | Documents the sanitizer heuristic addition for the java/sensitive-log query. |
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.
Fix #21653:
The sensitive-log query (CWE-532) lacked sanitizers for hashed or encrypted data, while the sibling cleartext-storage query (CWE-312) already recognized methods with "encrypt", "hash", or "digest" in their names as sanitizers (CleartextStorageQuery.qll:86).
This adds an EncryptionBarrier to SensitiveLoggingQuery that applies the same name-based heuristic, making the two queries consistent. Calls like DigestUtils.sha256Hex(password) or hashPassword(secret) are no longer flagged when their results are logged.