Skip to content

Log redacted+truncated HTTP bodies at debug level#187

Draft
parthban-db wants to merge 1 commit into
mainfrom
parthban-db/stack/bugbash-bug4-secret-logging
Draft

Log redacted+truncated HTTP bodies at debug level#187
parthban-db wants to merge 1 commit into
mainfrom
parthban-db/stack/bugbash-bug4-secret-logging

Conversation

@parthban-db
Copy link
Copy Markdown
Contributor

@parthban-db parthban-db commented Jun 3, 2026

🥞 Stacked PR

Use this link to review incremental changes.


Summary

Restores HTTP request/response body logging at debug level in the generated executeHttpCall / sendAndCheckError helpers, made secret-safe by redaction and truncation. This replaces the earlier approach of dropping the body from debug logs entirely. The behavior now matches the Go SDK: bodies are always logged at debug, but secret-bearing fields are redacted and every value is truncated.

Why

executeHttpCall previously logged the full decoded response body with no redaction, so endpoints like getSecret() leaked plaintext secrets into debug logs. The first fix dropped the body altogether, which also removed a useful debugging signal. The Go SDK keeps body logging on at debug and stays safe by redacting secret-bearing JSON keys (token, password, access_token, string_value, ...) to **REDACTED** and truncating every value to debugTruncateBytes. This PR ports that behavior, so bodies return without secrets reaching the logs.

What changed

  • New @databricks/sdk-core/logger/debug module (onlyNBytes, redactedDumpBody, redactHeaders, DEFAULT_DEBUG_TRUNCATE_BYTES), a hand-written, unit-tested port of the Go SDK's logger/httplog redaction and truncation logic, exported under the ./logger/debug subpath.
  • ClientOptions gains debugHeaders (default false) and debugTruncateBytes (default 96), mirroring Go's DebugHeaders / DebugTruncateBytes. Headers are logged only when debugHeaders is true, and Authorization-family headers are always redacted to REDACTED. Bodies are logged regardless of debugHeaders, matching Go; streaming bodies log a <stream> sentinel and are never drained.
  • Regenerated utils.ts and client.ts across all packages to thread the new options and emit the redacted body/header logs.
  • Deliberate divergences from Go: no env-var plumbing (the v2 JS SDK has no env-config layer yet; option names map cleanly to DATABRICKS_DEBUG_* for a future layer), and Authorization headers are always redacted (no DebugAuthorizationHeader opt-in), which is the safer default given this was a secret-leak fix.

How do you know it works?

Adds packages/core/tests/logger/debug.test.ts covering each redact key, nested objects, the array trailer, UTF-8 boundary truncation, header redaction, and the non-JSON/empty-body fallbacks. Adds packages/examples/tests/debug-logging.test.ts, an end-to-end test through a generated PostgresClient asserting the response body is logged with the secret field redacted (and not in plaintext) when a debug logger is supplied, nothing is logged with the default NoOpLogger, and headers appear only when debugHeaders is enabled with Authorization redacted. Validated locally: npm run build (87/87), @databricks/sdk-core tests (370 passing), @databricks/sdk-options (8) and @databricks/sdk-examples (20) tests passing, npm run typecheck (95/95), npm run lint (95/95), npm run format:check (87/87).

This pull request and its description were written by Isaac.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

Please ensure that the NEXT_CHANGELOG.md file is updated with any relevant changes.
If this is not necessary for your PR, please include the following in your PR description:
NO_CHANGELOG=true
and rerun the job.

@parthban-db parthban-db force-pushed the parthban-db/stack/bugbash-bug4-secret-logging branch from b9aaa84 to 97b23bc Compare June 4, 2026 13:04
Restores HTTP body logging in the generated executeHttpCall / sendAndCheckError helpers, which had been dropped entirely to avoid leaking plaintext secrets (e.g. getSecret()). Bodies are now logged at debug the way the Go SDK does it: secret-bearing JSON fields (token, password, access_token, string_value, ...) are replaced with **REDACTED** and every value is truncated to debugTruncateBytes, so secrets no longer reach the logs while the debugging signal returns.

Adds debugHeaders and debugTruncateBytes to ClientOptions (defaulting to false and 96, matching Go's DebugHeaders / DebugTruncateBytes). Headers are logged only when debugHeaders is true, and Authorization-family headers are always redacted to REDACTED. The redaction and truncation logic lives in a new, unit-tested @databricks/sdk-core/logger/debug module (onlyNBytes, redactedDumpBody, redactHeaders) exported under the ./logger/debug subpath.

Regenerates utils.ts and client.ts across all packages to thread the new options and emit the redacted body/header logs. Adds core unit tests for the redaction helpers and an examples integration test asserting the body is logged (redacted) at debug and headers only appear when debugHeaders is set.

Co-authored-by: Isaac
@parthban-db parthban-db force-pushed the parthban-db/stack/bugbash-bug4-secret-logging branch from 97b23bc to 7a3446a Compare June 4, 2026 13:35
@parthban-db parthban-db changed the title Stop logging HTTP response bodies in generated executeHttpCall Log redacted+truncated HTTP bodies at debug level Jun 4, 2026
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.

1 participant