Java: treat hash/encrypt/digest methods as sensitive-log sanitizers#21654
Merged
owen-mc merged 4 commits intogithub:mainfrom Apr 30, 2026
Merged
Java: treat hash/encrypt/digest methods as sensitive-log sanitizers#21654owen-mc merged 4 commits intogithub:mainfrom
owen-mc merged 4 commits 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. |
owen-mc
requested changes
Apr 15, 2026
Co-authored-by: Owen Mansel-Chan <62447351+owen-mc@users.noreply.github.com>
Address review feedback by moving the shared method-name-based encryption/hash/digest check into Sanitizers.qll, and reference it from both CleartextStorageQuery.qll and SensitiveLoggingQuery.qll instead of duplicating the definition.
…h-sanitizer # Conflicts: # java/ql/test/query-tests/security/CWE-532/SensitiveLogInfo.expected # java/ql/test/query-tests/security/CWE-532/Test.java
owen-mc
approved these changes
Apr 29, 2026
Contributor
|
I ran the relevant query on the top 1000 java repos. Without your PR there were 16,102 alerts and with your PR there were 16,086. So that's a reduction of 16, or about 1 for every 1000 alerts. They are definitely FPs, so this is worth merging. |
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.