Skip to content

fix(logging): redact and sanitize execution errors before logging - #1464

Merged
chaliy merged 1 commit into
mainfrom
2026-04-24-propose-fix-for-logging-vulnerability
Apr 25, 2026
Merged

chaliy merged 1 commit into
mainfrom
2026-04-24-propose-fix-for-logging-vulnerability

Conversation

@chaliy

@chaliy chaliy commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Motivation

  • Prevent leaking untrusted script data and log-injection via execution error logs which previously logged raw Error strings.
  • Ensure execution-failure messages go through the same LogConfig redaction and sanitization used elsewhere.

Description

  • Add format_error_for_log(error, &LogConfig) in crates/bashkit/src/logging_impl.rs that sanitizes control/newline chars, applies redact_value, detects embedded secret-like tokens and aggressively redacts, and truncates long values per config.
  • Re-export the new formatter via bashkit::logging and wire Bash::exec_impl to call logging::format_error_for_log before emitting the tracing::error! entry.
  • Add a regression unit test test_error_message_redacted_and_sanitized that verifies a grep-style error containing an API-key-like token plus a forged newline is redacted.

Testing

  • Ran the focused unit test cargo test -p bashkit --features logging test_error_message_redacted_and_sanitized which failed on the unsafe code path before the fix and passes after the change.
  • Ran the logging security test suite cargo test -p bashkit --features logging --test logging_security_tests and all tests passed (26 passed, 0 failed).
  • Ran cargo fmt --check and formatting check passed.

Codex Task

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 24, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 4b7d0fb Commit Preview URL Apr 25 2026, 02:19 AM

@chaliy
chaliy force-pushed the 2026-04-24-propose-fix-for-logging-vulnerability branch from 715738d to 4b7d0fb Compare April 25, 2026 02:19
@chaliy
chaliy merged commit 6f4823f into main Apr 25, 2026
34 checks passed
@chaliy
chaliy deleted the 2026-04-24-propose-fix-for-logging-vulnerability branch April 25, 2026 02:29
@codecov

codecov Bot commented Apr 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

chaliy added a commit that referenced this pull request May 30, 2026
)

### Motivation

- Prevent leaking untrusted script data and log-injection via execution
error logs which previously logged raw `Error` strings.
- Ensure execution-failure messages go through the same `LogConfig`
redaction and sanitization used elsewhere.

### Description

- Add `format_error_for_log(error, &LogConfig)` in
`crates/bashkit/src/logging_impl.rs` that sanitizes control/newline
chars, applies `redact_value`, detects embedded secret-like tokens and
aggressively redacts, and truncates long values per config.
- Re-export the new formatter via `bashkit::logging` and wire
`Bash::exec_impl` to call `logging::format_error_for_log` before
emitting the `tracing::error!` entry.
- Add a regression unit test `test_error_message_redacted_and_sanitized`
that verifies a grep-style error containing an API-key-like token plus a
forged newline is redacted.

### Testing

- Ran the focused unit test `cargo test -p bashkit --features logging
test_error_message_redacted_and_sanitized` which failed on the unsafe
code path before the fix and passes after the change.
- Ran the logging security test suite `cargo test -p bashkit --features
logging --test logging_security_tests` and all tests passed (26 passed,
0 failed).
- Ran `cargo fmt --check` and formatting check passed.

------
[Codex
Task](https://chatgpt.com/codex/cloud/tasks/task_e_69eaeee6fd50832bbb663a72bf26efa9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant