Skip to content

Redact bytes and bytearrays written through RedactedIO - #75129

Open
muditagrawal2007 wants to merge 3 commits into
apache:mainfrom
muditagrawal2007:fix/redactedio-bytes-leak
Open

muditagrawal2007 wants to merge 3 commits into
apache:mainfrom
muditagrawal2007:fix/redactedio-bytes-leak

Conversation

@muditagrawal2007

Copy link
Copy Markdown

RedactedIO masks registered secrets before writes reach stdout, but its write() and writelines() missed bytes / bytearray: those values fall through _redact() to the default return item, then got stringified as b'…secret…', which wrote the cleartext secret to the underlying stream.

The only production call site is airflow tasks test, which routes task output through RedactedIO. Any task that ever wrote bytes to sys.stdout — common with subprocess wrappers, log buffers, and some logging libraries — had its secrets printed verbatim, while looking like a redaction.

bytes and bytearray are now decoded as UTF-8 with errors="replace" before redact() sees them, so the existing pattern-based masker runs. The shared logic is factored into a module-level helper so write() and writelines() stay symmetric, and the permissive behavior for non-string types added by #72063 is preserved (covered by test_write_non_string_types_passthrough).

Tests cover bytes, bytearray, malformed UTF-8, mixed str/bytes in writelines, and the non-string passthrough.

closes: #75069

Was generative AI tooling used to co-author this PR?
  • Yes — Minimax-M3

Generated-by: Minimax-M3 following the guidelines

RedactedIO masks registered secrets before writes reach stdout. Its
write() and writelines() passed inputs through str(redact(...)), but
_redact() only walks str and container types -- bytes and bytearray fell
through to the default `return item` and were then stringified as
b'...secret...', which writes the cleartext secret to the underlying
stream.

The only production call site, airflow tasks test, wraps task execution
in redirect_stdout(RedactedIO()); any task whose code wrote bytes to
sys.stdout (subprocess output, log buffers, and some logging libraries)
printed its secrets verbatim.

Bytes and bytearray values are now decoded as UTF-8 with errors="replace"
before redact() sees them, so the existing pattern-based masker runs.
The change keeps the permissive behavior for non-string types added by
apache#72063 and factors the shared logic into a module-level helper so
write() and writelines() stay symmetric.

Closes: apache#75069

This branch has not been deployed

No deployments
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.

RedactedIO leaks secret bytes to stdout

1 participant