Skip to content

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

Merged
owen-mc merged 4 commits intogithub:mainfrom
MarkLee131:fix/sensitive-log-hash-sanitizer
Apr 30, 2026
Merged

Java: treat hash/encrypt/digest methods as sensitive-log sanitizers#21654
owen-mc merged 4 commits 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.

Comment thread java/ql/test/query-tests/security/CWE-532/Test.java Outdated
Comment thread java/ql/lib/semmle/code/java/security/SensitiveLoggingQuery.qll
MarkLee131 and others added 3 commits April 29, 2026 20:53
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
@MarkLee131 MarkLee131 requested a review from owen-mc April 29, 2026 13:02
@owen-mc
Copy link
Copy Markdown
Contributor

owen-mc commented Apr 30, 2026

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.

@owen-mc owen-mc merged commit 87c35e6 into github:main Apr 30, 2026
21 checks passed
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

3 participants