Skip to content

Redact sensitive SQL password phrases#18754

Merged
trask merged 17 commits into
open-telemetry:mainfrom
trask:fix-sap-hana-password-sanitization
May 18, 2026
Merged

Redact sensitive SQL password phrases#18754
trask merged 17 commits into
open-telemetry:mainfrom
trask:fix-sap-hana-password-sanitization

Conversation

@trask
Copy link
Copy Markdown
Member

@trask trask commented May 14, 2026

Redact values following sensitive SQL password phrases in non-data statements so SAP HANA administrative commands and Oracle-style IDENTIFIED BY clauses do not expose unquoted or double-quoted passwords in sanitized query text. CREATE/ALTER USER statements now redact at PASSWORD or IDENTIFIED BY instead of stopping at USER, and regression coverage includes the additional password-bearing forms plus controls for normal password column usage.

@trask trask force-pushed the fix-sap-hana-password-sanitization branch from 4169833 to fb9d19f Compare May 14, 2026 22:25
@trask trask force-pushed the fix-sap-hana-password-sanitization branch from fb9d19f to 137caa9 Compare May 14, 2026 22:30
@trask trask changed the title Redact password values in SQL sanitizer Redact sensitive SQL password phrases May 14, 2026
@trask trask marked this pull request as ready for review May 14, 2026 23:09
@trask trask requested a review from a team as a code owner May 14, 2026 23:09
Copilot AI review requested due to automatic review settings May 14, 2026 23:09
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 tightens SQL query sanitization to better redact plaintext passwords in administrative/non-data SQL statements (e.g., SAP HANA ... PASSWORD ... and Oracle-style IDENTIFIED BY ...) while preserving more useful sanitized query text and query summaries.

Changes:

  • Update SQL sanitizer lexers to truncate (redact remainder) after PASSWORD and IDENTIFIED BY in non-data contexts.
  • Adjust handling of USER to improve CREATE/ALTER USER query summary extraction.
  • Expand regression tests to cover additional password-bearing admin forms and add controls for non-sensitive password/identified_by identifiers.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex Adds PASSWORD/IDENTIFIED BY truncation logic and a dedicated USER keyword handler.
instrumentation-api-incubator/src/main/jflex/SqlSanitizerWithSummary.jflex Mirrors the truncation logic in the summary-producing sanitizer and updates USER handling.
instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlQueryAnalyzerTest.java Extends sensitive-statement test coverage for additional password forms and non-sensitive controls.
Comments suppressed due to low confidence (2)

instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex:517

  • shouldSanitizeRemainderAfterSensitivePhrase() is used to trigger early truncation when encountering the token PASSWORD. Because it only checks the operation type, any non-DML statement (e.g., CREATE TABLE ...) that contains an unquoted identifier named password will now be truncated at that point, even when no secret value follows. This looks like an overbroad match for a keyword that is also a common identifier; consider adding additional context checks (e.g., only trigger at top level like parenLevel == 0, and/or only when the grammar position indicates a password clause) and add a regression test for CREATE TABLE users (password VARCHAR(...)).
  "PASSWORD" {
          appendCurrentFragment();
          if (shouldSanitizeRemainderAfterSensitivePhrase()) {
            builder.append(" ?");
            return YYEOF;
          }

instrumentation-api-incubator/src/main/jflex/SqlSanitizerWithSummary.jflex:1038

  • Similar to the non-summary sanitizer, truncating on the bare token PASSWORD for any non-DML operation is likely overbroad for query-summary mode too (e.g., CREATE TABLE users (password VARCHAR(...)) would stop at the column name). Consider tightening the condition (e.g., parenLevel == 0 and/or only in known admin/DDL password-clause contexts) and adding a regression test that ensures common schema DDL with a password column is not truncated.
  "PASSWORD" {
          appendCurrentFragment();
          if (shouldSanitizeRemainderAfterSensitivePhrase()) {
            builder.append(" ?");
            return YYEOF;
          }

Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex Outdated
Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizerWithSummary.jflex Outdated
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizerWithSummary.jflex Outdated
Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizerWithSummary.jflex Outdated
Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex
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

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

Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex Outdated
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

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

Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex Outdated
}
if (isOverLimit()) return YYEOF;
}
"IDENTIFIED" {WHITESPACE}+ "BY" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess you could have a comment between identified and by, but I think we can ignore that

Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex Outdated
Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex Outdated
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizerWithSummary.jflex Outdated
Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex Outdated
@trask trask requested a review from laurit May 15, 2026 15:49
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex Outdated
Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizerWithSummary.jflex Outdated
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

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

Comments suppressed due to low confidence (1)

instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex:474

  • [Security] The admin-keyword rules only enable PASSWORD/IDENTIFIED BY remainder redaction when operation == NoOp.INSTANCE. After a semicolon, operation is intentionally not reset (old-semconv extraction sticks to the first statement), so a sensitive admin/DDL command that appears in a subsequent statement (e.g., SELECT 1; CREATE USER u PASSWORD secret) will not enable redaction and can leak unquoted passwords in the sanitized query text. Consider tracking “start of statement” separately (reset on ; outside comments, ignoring whitespace) and using that to gate these flags, instead of operation == NoOp.INSTANCE.
  "CONNECT" | "VALIDATE" | "CHECK" | "EXPORT" | "IMPORT" | "RECOVER" {
          if (!insideComment && operation == NoOp.INSTANCE) {
            passwordSanitizationEnabled = true;
            identifiedBySanitizationEnabled = true;
          }

Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex
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

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

Comment thread instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@trask trask merged commit 7ac7fa6 into open-telemetry:main May 18, 2026
99 checks passed
@trask trask deleted the fix-sap-hana-password-sanitization branch May 18, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants