ShivanshhhG opened a new pull request, #75077:
URL: https://github.com/apache/airflow/pull/75077

   `RedactedIO` exists so that output produced by user code is masked before it 
reaches stdout (its docstring states *"Writes to stdout will be redacted"*).
   
   Previously, `write()` and `writelines()` passed inputs directly to 
`redact()`. Because `_redact` operates on string and container types, `bytes` 
and `bytearray` values fell through unredacted to `return item` and were 
subsequently converted to string via `str(b"...")` in `write()` and 
`writelines()`. This caused cleartext secrets to be leaked to stdout wrapped in 
a Python `b'...' ` representation (e.g. during `airflow tasks test`).
   
   ### Fix
   - Introduced a `_redact_value` helper method on `RedactedIO` that decodes 
`bytes` and `bytearray` objects to UTF-8 (`errors="replace"`) before invoking 
`redact()`.
   - Preserved existing behavior for `str` and other non-string types.
   - Updated `write` and `writelines` to use `_redact_value`.
   
   ### Testing
   - Added unit tests in 
`shared/secrets_masker/tests/secrets_masker/test_secrets_masker.py` under 
`TestRedactedIO`:
     - `test_write_bytes`: asserts secrets in bytes written to `write()` are 
masked.
     - `test_write_bytearray`: asserts secrets in bytearrays written to 
`write()` are masked.
     - `test_write_invalid_utf8_bytes`: asserts invalid UTF-8 byte sequences 
with secrets are handled safely without raising errors.
     - `test_write_non_string_types`: asserts non-string/non-byte types (e.g. 
ints) preserve stringification.
     - `test_writelines_bytes`: asserts secrets in bytes written to 
`writelines()` are masked.
     - `test_writelines_bytearray`: asserts secrets in bytearrays written to 
`writelines()` are masked.
     - `test_writelines_mixed`: asserts mixed strings and bytes written to 
`writelines()` are masked.
   - All 179 unit tests in `shared/secrets_masker` pass.
   - `ruff check`, `ruff format --check`, and `mypy src` pass cleanly with zero 
errors.
   
   Closes: #75069
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Antigravity following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to