Repository navigation
fix(proxy): redact plaintext in logs unless built with log-plaintext - #534
Conversation
cipherstash-agent
left a comment
There was a problem hiding this comment.
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) majordebug!(target: MIGRATE, ?config)printsTandemConfigthrough derivedDebug, includingauth.client_access_key,encrypt.client_keyand an inlineTlsConfig::Pem.private_key_pem. WithCS_LOG__MIGRATE_LEVEL=debugon 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 fieldsProtected<String>likeDatabaseConfig.password, or give the types a redactingDebug.
Source: rust-security agent · claude-opus-5-5; mattpocock code-review agent · claude-opus-5-5packages/cipherstash-proxy/src/postgresql/middleware/frontend.rs:230(outside diff) minor The "Query Handler Error" and "Parse Handler Error" (:270) warnings logerr.to_string(), and sqlparser echoes the unexpected token:SELECT * FROM users WHERE email = '[email protected]' 'ssn-123-45-6789'logsfound: 'ssn-123-45-6789'at the defaultinfolevel. The PR defers this, but the CHANGELOG says values are redacted "at every log level". Wrap the field inSensitiveor log only the variant, or narrow the CHANGELOG claim.
Source: code-review · claude-opus-5-5
Generated by Claude Code
tobyhede
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
cipherstash-bot
left a comment
There was a problem hiding this comment.
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 ofwarn_if_verbose.packages/cipherstash-proxy/src/postgresql/rewrite/data_row.rs:154— Optional: no test checks thatlog_deserialise_errordoes not log decrypt payload content.packages/cipherstash-proxy/src/cli/migrate/mod.rs:210— Optional: themigratecommand'ssql,update_sqlandrecordslog 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()), |
There was a problem hiding this comment.
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_handleris theBackendmethod under test. The test expects it to write the "Database returned an error" log, where this change adds theSensitivewrap.create_backend()supplies theBackendfor the test.invalid_sql_statementbuilds the error response from the message text.SECRETis the test value that the test puts in that message.capture_trace_logsruns the call and returns the logs.assert_secret_logged_only_with_log_plaintextchecks thatSECRETappears in the logs only whenlog-plaintextis 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), |
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
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
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.
48cb945 to
8c13347
Compare
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_LEVELorCS_LOG__ENCODING_LEVELtodebugto 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 thelog-plaintextCargo feature. Release builds redact even with--all-features.Changes
log::Sensitive<T>type prints<redacted>fromDebugandDisplayunless a development build enableslog-plaintext. Vitamin C'sOpaqueDebugalways redacts, so it could not be switched on for development builds.debug!field that can carry a value now goes throughSensitive: 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 themigratecommand's SQL. Literal JSON selector keys redact themselves inDebug, so logged statements and portals are covered too.infobecause its debug and trace output includes SQL and literals.debugortrace, lists them, and says whether this build logs plaintext. If theCONFIGtarget would filter the warning out, it goes to stderr instead.target = MAPPERwas a field rather than the log target.mise run proxynow builds withlog-plaintext, so local logs still show values. A newmise run test:unit:log-plaintexttask, called frommise run test, runs the redaction tests with the feature on.log_redaction.rssends 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 theproxy-tlscontainer's logs and checks the value never appears. The integration run sets every log target totracefor this, andtests/docker-compose.ymlnow passes every per-target level toproxy-tls. The test runs only whenPROXY_LOG_CONTAINERnames the container; it skips locally without it, and fails in CI without it so it cannot stop running unnoticed.DEVELOPMENT.md, the logging section ofdocs/reference/index.md, and aCHANGELOG.mdentry 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.Sensitivewrap, or the EQL Mapper cap, makes the matching unit test fail; restoring it makes it pass.PROXY_LOG_CONTAINERand fails withCI=trueset.tracemakes the integration Proxy much more verbose; if a dependency logs values at trace, the new test will fail and show it.Review notes
packages/cipherstash-proxy/src/log/sensitive.rsandlog/subscriber.rs, then the call sites inpostgresql/middleware/frontend.rs.tests/docker-compose.ymland in thetest:integrationtask inmise.toml, or the end-to-end test will not cover it.DEVELOPMENT.mdsays so.warn!events that include EQL Mapper error text, such as "Unmappable statement", may quote parts of the SQL.migrate --verbosestill logs primary-key values atinfo, 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.