Skip to content

fix(proxy): redact plaintext in logs unless built with log-plaintext - #534

Merged
tobyhede merged 8 commits into
mainfrom
tobyhede/proxy-release-builds-must-never-log-plaintext-whatever-the-log-level
Dec 3, 2026
Merged

tobyhede merged 8 commits into
mainfrom
tobyhede/proxy-release-builds-must-never-log-plaintext-whatever-the-log-level

Conversation

@tobyhede

@tobyhede tobyhede commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Release builds of Proxy no longer write customer data to their logs, at any log level.
Before this change, an operator who set a log target such as CS_LOG__MAPPER_LEVEL or CS_LOG__ENCODING_LEVEL to debug to chase a problem could send plaintext values, bound query parameters, SQL literals and full SQL statements into their log pipeline.
Now those values print as <redacted>, unless a development build enables the log-plaintext Cargo feature. Release builds redact even with --all-features.

Changes

  • Redaction wrapper: a new log::Sensitive<T> type prints <redacted> from Debug and Display unless a development build enables log-plaintext. Vitamin C's OpaqueDebug always redacts, so it could not be switched on for development builds.
  • Log fields: every debug! field that can carry a value now goes through Sensitive: plaintexts, bound parameters, literals, JSON selector values and paths, SQL text, rewritten Parse, Bind and Query messages, passthrough protocol messages, PostgreSQL error message text, and the migrate command's SQL. Literal JSON selector keys redact themselves in Debug, so logged statements and portals are covered too.
  • Dependencies: in redacted builds, Proxy caps EQL Mapper at info because its debug and trace output includes SQL and literals.
  • Startup warning: Proxy warns when the default level or any target is at debug or trace, lists them, and says whether this build logs plaintext. If the CONFIG target would filter the warning out, it goes to stderr instead.
  • Bug fix: the "Convert plaintext to postgres_type" event logged the plaintext, and its target = MAPPER was a field rather than the log target.
  • Development workflow: mise run proxy now builds with log-plaintext, so local logs still show values. A new mise run test:unit:log-plaintext task, called from mise run test, runs the redaction tests with the feature on.
  • Integration test: log_redaction.rs sends a unique value through Proxy in four ways (extended protocol insert and selects with bound parameters, simple protocol insert and selects with literals), then reads the proxy-tls container's logs and checks the value never appears. The integration run sets every log target to trace for this, and tests/docker-compose.yml now passes every per-target level to proxy-tls. The test runs only when PROXY_LOG_CONTAINER names the container; it skips locally without it, and fails in CI without it so it cannot stop running unnoticed.
  • Docs: DEVELOPMENT.md, the logging section of docs/reference/index.md, and a CHANGELOG.md entry under Security.

Verification

  • cargo nextest run -E "not package(cipherstash-proxy-integration)": 807 passed, 6 skipped.
  • cargo nextest run -p cipherstash-proxy --features log-plaintext: 546 passed, which shows the same events do show values with the feature on.
  • cargo clippy --all --no-deps --all-targets -- -D warnings, with and without --all-features: clean.
  • cargo fmt --all --check: clean.
  • Red checks: removing a Sensitive wrap, or the EQL Mapper cap, makes the matching unit test fail; restoring it makes it pass.
  • The integration test skips without PROXY_LOG_CONTAINER and fails with CI=true set.
  • Not run: the integration suite, including the new end-to-end test, because Docker and the integration credentials were not available locally. CI on this pull request is its first run. Setting every target to trace makes the integration Proxy much more verbose; if a dependency logs values at trace, the new test will fail and show it.

Review notes

  • Start with packages/cipherstash-proxy/src/log/sensitive.rs and log/subscriber.rs, then the call sites in postgresql/middleware/frontend.rs.
  • Adding a log target now also needs a line in tests/docker-compose.yml and in the test:integration task in mise.toml, or the end-to-end test will not cover it. DEVELOPMENT.md says so.
  • Deferred: warn! events that include EQL Mapper error text, such as "Unmappable statement", may quote parts of the SQL. migrate --verbose still logs primary-key values at info, only when that flag is passed.

Acknowledgment

By submitting this pull request, I confirm that CipherStash can use, modify, copy, and redistribute this contribution, under the terms of CipherStash's choice.

@tobyhede
tobyhede marked this pull request as ready for review December 2, 2026 23:14

@cipherstash-agent cipherstash-agent left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review attestation

Reviewed 9825205 · posted from Claude Code (scheduled routine) · claude-opus-5-5 · code-review effort medium
Sources: code-review · claude-opus-5-5; rust-security agent · claude-opus-5-5; mattpocock code-review agent · claude-opus-5-5
Skills: code-review, company-skills:rust-security, mattpocock-skills:code-review, company-skills:review-cross-check

Findings (8): 2 major, 6 minor — 6 inline, 2 below. Each was verified at 9825205; there was no earlier review feedback to cross-check against.

  • packages/cipherstash-proxy/src/cli/migrate/mod.rs:68 (outside diff) major debug!(target: MIGRATE, ?config) prints TandemConfig through derived Debug, including auth.client_access_key, encrypt.client_key and an inline TlsConfig::Pem.private_key_pem. With CS_LOG__MIGRATE_LEVEL=debug on a release build, the new startup warning says "Values are redacted" and the next line logs the credentials. This predates the PR but contradicts its CHANGELOG; make those fields Protected<String> like DatabaseConfig.password, or give the types a redacting Debug.
    Source: rust-security agent · claude-opus-5-5; mattpocock code-review agent · claude-opus-5-5
  • packages/cipherstash-proxy/src/postgresql/middleware/frontend.rs:230 (outside diff) minor The "Query Handler Error" and "Parse Handler Error" (:270) warnings log err.to_string(), and sqlparser echoes the unexpected token: SELECT * FROM users WHERE email = '[email protected]' 'ssn-123-45-6789' logs found: 'ssn-123-45-6789' at the default info level. The PR defers this, but the CHANGELOG says values are redacted "at every log level". Wrap the field in Sensitive or log only the variant, or narrow the CHANGELOG claim.
    Source: code-review · claude-opus-5-5

Generated by Claude Code

Comment thread CHANGELOG.md Resolved
Comment thread mise.toml Resolved

@tobyhede tobyhede left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review attestation

Rechecked the three findings from 9825205e at 043d11e2. The JSON selector and parser warning findings are fixed. Verification was by code inspection.

Posted from Codex · GPT-6 · effort unknown
Source: review-agent · GPT-6
Skills: review-agent, review-cross-check

Findings (1): 1 major, inline.

@tobyhede tobyhede left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review attestation

Reviewed 043d11e2 by code inspection. Posted from Codex · GPT-6 · effort unknown.
Source: review-agent · GPT-6
Skill: review-agent

Three findings. The major release-profile finding is already posted at this commit. Two minor findings follow inline.

Comment thread DEVELOPMENT.md Resolved

@cipherstash-bot cipherstash-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Recommendation: 🟢 merge as it is

Nothing blocks this merge. The redaction wrapper, the release-profile check and the EQL Mapper cap look correct. Three comments can wait for a follow-up: a missing test for the PostgreSQL error message, the loss of error class in handler warnings, and the #[ignore] on the release test.


Other findings not posted as comments

  • packages/cipherstash-proxy/src/postgresql/rewrite/bind.rs:190 — Fix in a follow-up: the "Fused JSON value selector" and "Composed JSON accessor path" debug events have no redaction test.
  • packages/cipherstash-proxy/src/log/mod.rs:75 — Optional: no test runs the stderr branch of warn_if_verbose.
  • packages/cipherstash-proxy/src/postgresql/rewrite/data_row.rs:154 — Optional: no test checks that log_deserialise_error does not log decrypt payload content.
  • packages/cipherstash-proxy/src/cli/migrate/mod.rs:210 — Optional: the migrate command's sql, update_sql and records log fields have no redaction test.
How this review was made
Agent Model Review type Result
claude claude-opus-5-5 test-gap 3 found, 1 posted
claude claude-opus-5-5 rust 2 found, 2 posted
codex gpt-5.6-terra test-gap 1 found, 1 posted
codex gpt-5.6-terra rust 0 found, 0 posted

Synthesis: claude-sonnet-5-5 merged the findings, removed duplicates and dropped findings it could not confirm in the code. 1 posted finding(s) were raised by two or more models.

Plain language: claude-sonnet-5-5 read every comment as a new reader would. 1 comment(s) had a problem that stopped the reader acting; it rewrote 1.

Stack: not part of a stack.

Context loaded: the description, 0 linked issue(s) and 12 discussion entries.

msg = "Database returned an error",
code = %field(b'C').unwrap_or_default(),
error = %field(b'M').unwrap_or_default(),
error = %Sensitive(field(b'M').unwrap_or_default()),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fix in a follow-up: no test checks that the proxy redacts the PostgreSQL error message in the "Database returned an error" log.

Impact: PostgreSQL puts values in the M field, which holds the error message. One example is invalid input syntax for type integer: "<value>". If someone removes this Sensitive wrap, every unit test still passes. The integration test in log_redaction.rs also passes, because it sends no query that fails.

Evidence: The backend tests in backend.rs check only the forwarded message. They do not read the logs.

Fix: Add a test beside the backend tests in backend.rs that captures the logs:

#[test]
fn database_error_message_is_logged_only_with_log_plaintext() {
    use crate::test_helpers::{
        assert_secret_logged_only_with_log_plaintext, capture_trace_logs, SECRET,
    };

    let mut backend = create_backend();
    let response = crate::postgresql::diagnostics::invalid_sql_statement(
        format!("invalid literal {SECRET}"),
    );
    let logs = capture_trace_logs(|| backend.error_response_handler(&response));

    assert!(logs.contains("Database returned an error"), "{logs}");
    assert_secret_logged_only_with_log_plaintext(&logs);
}

The test uses these names:

  • error_response_handler is the Backend method under test. The test expects it to write the "Database returned an error" log, where this change adds the Sensitive wrap.
  • create_backend() supplies the Backend for the test.
  • invalid_sql_statement builds the error response from the message text.
  • SECRET is the test value that the test puts in that message.
  • capture_trace_logs runs the call and returns the logs.
  • assert_secret_logged_only_with_log_plaintext checks that SECRET appears in the logs only when log-plaintext is enabled.

This comment does not confirm that create_backend(), invalid_sql_statement or the three crate::test_helpers items already exist. Search for them first, and write any that are missing.

Found by 2 models: claude, codex

client_id = self.context.client_id,
msg = "Query Handler Error",
error = ?err.to_string(),
error = %Sensitive(&err),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fix in a follow-up: release builds log error=<redacted> for every Query and Parse handler failure, so operators lose all error detail at warn.

Impact: Sensitive(&err) hides the whole error, not only the SQL part. A ZeroKMS failure, an unknown column and a type-check failure all print the same line. An operator cannot tell the error class from the log, and debug logging also prints <redacted>.

Evidence: error_to_response(err) on the next lines already maps the error to a DiagnosticResponse with a SQLSTATE code. That code is not a value. backend.rs already logs code unredacted next to a redacted error.

Fix: Build the response first. Log its SQLSTATE code unredacted, and keep the message in Sensitive. Do the same for "Parse Handler Error". Another safe field is the error variant name.

Found by 1 model: claude


// CI runs this test explicitly under --release --all-features.
#[test]
#[ignore = "requires the release profile with all features"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Optional: the release redaction test uses #[ignore], so it runs only when someone selects it by name.

Impact: A plain cargo test --release --all-features does not run it. A development build that runs ignored tests with log-plaintext makes it fail, because that build logs plaintext on purpose. Only the one CI line in test.yml checks the release guarantee.

Evidence: build.rs sets proxy_dev_profile only for the debug profile. The other tests in this module already use cfg.

Fix: Replace #[ignore] with #[cfg(not(proxy_dev_profile))]. Then drop --ignored from the CI step.

Found by 1 model: claude

@auxesis auxesis 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.

Thanks for this @tobyhede.

Approving in anticipation of the fixes being implemented.

Debug and trace events could write plaintexts, bound parameters,
literals, SQL text and protocol messages to the logs of a release
build when an operator raised a log level.

Add a `log::Sensitive` wrapper whose Debug and Display print
`<redacted>` unless the new `log-plaintext` Cargo feature is compiled
in, and wrap every log field that can carry a value. Redacted builds
also cap the tokio-postgres and EQL Mapper targets, whose debug and
trace output carries query text and literals. Proxy now warns at
startup when any target is at debug or trace, and says whether the
build logs plaintext.

`mise run proxy` enables the feature for local development. The
integration run sets every target to trace and checks that a
distinctive value sent through both protocols never reaches the
Proxy container logs.

Closes CIP-5752
…iable

Proxy reads every CS_ variable as configuration, and this one is only
for the integration test runner.
A skipped Rust test reports as a pass, so dropping PROXY_LOG_CONTAINER
from the integration task would have silently stopped the check.
The MAPPER debug event logged the param plan's JSON selector literals,
and the Query and Parse handler warnings logged sqlparser errors that
echo SQL literals at the default level. Both are now wrapped in
Sensitive.

Drop tokio_postgres from the dependency targets: it logs through the
log crate, which Proxy does not bridge into tracing.
migrate logs the whole TandemConfig at debug, which printed the client
access key, client key and inline TLS private key. Their Debug output
now prints <redacted> in every build. The --verbose record list is
wrapped in Sensitive.
A child mise run reloads CS_LOG__* from mise.local.toml, so the exported
trace levels were silently overridden locally. PROXY_LOG_FORCE_LEVEL
now takes precedence in the proxy-tls service, and the test asserts
every log target appears in the startup warning.
Require a development profile before enabling plaintext logging. Exercise the all-features release build in CI and read the configured targets from the structured startup warning so unrelated log entries cannot satisfy the integration check.
@tobyhede
tobyhede force-pushed the tobyhede/proxy-release-builds-must-never-log-plaintext-whatever-the-log-level branch from 48cb945 to 8c13347 Compare December 3, 2026 09:25
@tobyhede
tobyhede merged commit 921a8db into main Dec 3, 2026
10 checks passed
@tobyhede
tobyhede deleted the tobyhede/proxy-release-builds-must-never-log-plaintext-whatever-the-log-level branch December 3, 2026 11:00
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.

4 participants