Skip to content

Omit sensitive SQL values from query diagnostics - #157

Open
pquerna wants to merge 1 commit into
mainfrom
paul.querna/sql-query-log-redaction
Open

pquerna wants to merge 1 commit into
mainfrom
paul.querna/sql-query-log-redaction

Conversation

@pquerna

@pquerna pquerna commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Remove SQL text, bound argument values, and variable maps from application-owned query diagnostics. These fields can contain account-creation and password-rotation credentials, including when SQL uses bind parameters or hashes the password inside the database.

Keep operation, query index, argument count, affected-row count, and transaction metadata. Validation failures identify the query by index instead of returning rendered SQL. Query construction, arguments sent to the database, returned credentials, and idempotency error identity remain unchanged.

Regression proof

TestQueryLoggingDoesNotExposeValues exercises eleven real SQLite-backed paths: ordinary and grant execution, validation, no-rows validation, DDL idempotency, principal-exists checks, row-query success/failure, inline SQL values, and grant replacement.

TestAccountCredentialsStayOutOfQueryLogs invokes actual account creation and rotation, verifies the returned generated password equals the value stored by the fixture database, and verifies it is absent from captured logs. Assertions inspect both encoded output and recursively decoded JSON fields, including quote-containing values.

The identical tests fail against the original query.go using Go's file overlay and pass with the fix. Tests also assert that arguments still reach SQL execution unchanged; this is not only a logger-helper test.

go test ./pkg/bsql -run '^(TestQueryLoggingDoesNotExposeValues|TestAccountCredentialsStayOutOfQueryLogs)$' -count=1 -v

Scope and limits

This removes explicit application-owned SQL/argument/variable payloads. Database-driver errors remain propagated and can contain statement details; this PR does not claim comprehensive downstream error sanitization or an audit of every row/expression diagnostic. The README states that residual risk.

No dependencies, public configuration schema, provisioning API, or database behavior change. Fixture proof uses in-process SQLite, not a live vendor or deployed connector. Native DB2-tagged builds and external database workflows were not exercised.

Checks

  • Worker full make test, make build, and make lint: passed; lint reported zero issues.
  • Parent reviewed the exact commit and tests, integrated it into the original checkout, and passed the account/query regressions, local rebuild, and CLI smoke there.

Replace SQL, bound arguments and variable maps in query diagnostics with operation and count metadata. Use query indices in validation failures instead of rendered SQL. Exercise real SQLite query, exec, create-account and credential-rotation paths with captured secrets.

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
@pquerna
pquerna requested a review from a team November 19, 2026 17:52
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor
Superseded — see the current review report for commit 199c80720c11

Connector PR Review: Omit sensitive SQL values from query diagnostics

Blocking Issues: 0 | Suggestions: 0 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base 4ac5716f73e6.
Review mode: full
View review run

Review Summary

This PR stops pkg/bsql/query.go from logging rendered SQL, bound argument values, and variable maps. That covers the principal-exists check, validation queries, provisioning and grant exec loops, runQuery success and error logs, and the grant-replace info log. Those logs now record the operation, query index, argument count, rows affected, and use_tx. Validation no-rows errors now name the query by index instead of quoting the SQL. ErrValidationNoRows stays wrapped with %w, and no callers or tests depend on the old error text. I scanned the full PR diff for security and correctness issues and grepped every l.Debug/Info/Warn/Error call under pkg/. No other call site still emits query, argument, or variable payloads.

The repo-local criteria were applied. Section A (log levels): no levels changed, and the existing l.Error plus return in runQuery is unchanged except that its fields were removed. H5 (no secrets in logs) is what this PR improves. Section S (sync data loss), the provisioning P/PR rules, breaking changes B1–B9, and dependency checks do not apply: no List/Grants control flow, Grant/Revoke entity sourcing, IDs, or go.mod changed.

The new tests run against real SQLite paths. They check the encoded log output and the recursively decoded JSON values, and they also confirm that arguments still reach the database. The diff gives the following residual risks, all of which the PR and README call out as out of scope:

  • Driver errors are passed through zap.Error(err) in runQuery and can still carry statement details.
  • The existing debug log at query.go:1091 emits grant-replace result row data (zap.Any("row", ...)). That data is grant rows, not credential inputs.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

None.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Connector PR Review: Omit sensitive SQL values from query diagnostics

Blocking Issues: 0 | Suggestions: 0 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base 4ac5716f73e6.
Review mode: full
View review run

Review Summary

This PR stops pkg/bsql/query.go from logging rendered SQL, bound argument values, and variable maps. That covers the principal-exists check, validation queries, provisioning and grant exec loops, runQuery success and error logs, and the grant-replace info log. Those logs now record the operation, query index, argument count, rows affected, and use_tx. Validation no-rows errors now name the query by index instead of quoting the SQL. ErrValidationNoRows stays wrapped with %w, and no callers or tests depend on the old error text. I scanned the full PR diff for security and correctness issues and grepped every l.Debug/Info/Warn/Error call under pkg/. No other call site still emits query, argument, or variable payloads.

The repo-local criteria were applied. Section A (log levels): no levels changed, and the existing l.Error plus return in runQuery is unchanged except that its fields were removed. H5 (no secrets in logs) is what this PR improves. Section S (sync data loss), the provisioning P/PR rules, breaking changes B1–B9, and dependency checks do not apply: no List/Grants control flow, Grant/Revoke entity sourcing, IDs, or go.mod changed.

The new tests run against real SQLite paths. They check the encoded log output and the recursively decoded JSON values, and they also confirm that arguments still reach the database. The diff gives the following residual risks, all of which the PR and README call out as out of scope:

  • Driver errors are passed through zap.Error(err) in runQuery and can still carry statement details.
  • The existing debug log at query.go:1091 emits grant-replace result row data (zap.Any("row", ...)). That data is grant rows, not credential inputs.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

None.


Reviewed commit: 199c80720c11

@github-actions github-actions Bot left a comment

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.

No blocking issues found — see the full review report

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.

2 participants