Skip to content

Conversation

@aegilops
Copy link
Contributor

@aegilops aegilops commented Oct 31, 2025

Logging of sensitive data can be mitigated by taking a substring of the data.

This affects the library used by java/sensitive-log (CWE 532).

The exact length suitable will vary by application, but this change takes a conservative approach and allows either substring or take/takeLast of up to 7 characters.

Complex redaction with a regular expression, replacement of particular characters, a substring not at the start or end of the string, or a conditional substring (such as with Apache StringUtils) are not supported in this sanitizer.

There is a new abstraction for sanitizer barriers, along with logic to detect substring operations that restrict logged data to a safe length in both Java and Kotlin code. The existing sanitizers are pulled into a new class called GenericSanitizer, which implements the new abstract class, alongside the new sanitizer.

The safe length restriction must be done in the analyzed code with a compile-time constant integer, but the integer can reach the substring operation using taint.

@github-actions github-actions bot added the Java label Oct 31, 2025
@aegilops aegilops changed the title Added java-kotlin Sensitive Logging barriers (substrings) java: Added Java/Kotlin Sensitive Logging barriers (substrings) Nov 14, 2025
@aegilops aegilops marked this pull request as ready for review November 15, 2025 09:43
@aegilops aegilops requested a review from a team as a code owner November 15, 2025 09:43
Copilot AI review requested due to automatic review settings November 15, 2025 09:43
Copilot finished reviewing on behalf of aegilops November 15, 2025 09:46
Copy link
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 adds support for detecting substring operations as sanitizer barriers in sensitive logging analysis for both Java and Kotlin. The implementation takes a conservative approach by allowing substring operations that extract up to 7 characters, which can help mitigate the logging of sensitive data.

Key Changes:

  • Introduced abstract SensitiveLoggerBarrier class for sanitizer barriers
  • Implemented substring-based sanitizers supporting Java String.substring() and Kotlin take()/takeLast() methods
  • Refactored existing sanitizers into a new GenericSanitizer class

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
java/ql/lib/semmle/code/java/security/SensitiveLoggingQuery.qll Core implementation adding SensitiveLoggerBarrier abstraction, SensitiveLoggerSanitizerCalled for substring operations with helper predicates, IntegerToArgConfig for constant propagation, and refactored GenericSanitizer
java/ql/test/query-tests/security/CWE-532/Test.java Added test cases demonstrating safe usage of substring(4) and substring(0,4) on sensitive auth tokens

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

/**
* A sanitizer that may remove sensitive information from a string before logging.
*
* It allows for substring operations taking the first N (or last N, for Kotlin) characters, limited to 7 or fewer.
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

[nitpick] Extra space before "It allows". The documentation comment should have consistent spacing - either one space after the asterisk for all lines, or align the text.

Suggested change
* It allows for substring operations taking the first N (or last N, for Kotlin) characters, limited to 7 or fewer.
* It allows for substring operations taking the first N (or last N, for Kotlin) characters, limited to 7 or fewer.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant