Skip to content

Java: treat hash/encrypt/digest methods as sensitive-log sanitizers#21654

Open
MarkLee131 wants to merge 1 commit intogithub:mainfrom
MarkLee131:fix/sensitive-log-hash-sanitizer
Open

Java: treat hash/encrypt/digest methods as sensitive-log sanitizers#21654
MarkLee131 wants to merge 1 commit intogithub:mainfrom
MarkLee131:fix/sensitive-log-hash-sanitizer

Conversation

@MarkLee131
Copy link
Copy Markdown
Contributor

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.

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.
Copilot AI review requested due to automatic review settings April 4, 2026 13:52
@MarkLee131 MarkLee131 requested a review from a team as a code owner April 4, 2026 13:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 EncryptionBarrier to the java/sensitive-log query to stop flows through method calls whose names contain encrypt, hash, or digest.
  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

java/sensitive-log: missing sanitizer for hashed/encrypted data

2 participants