Skip to content

common(feat[logging]): Let callers choose the logged argv redactor - #906

Draft
tony wants to merge 3 commits into
masterfrom
example/866-mask-all-opt-out
Draft

tony wants to merge 3 commits into
masterfrom
example/866-mask-all-opt-out

Conversation

@tony

@tony tony commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Example only. This is one of two alternatives to #898 for the rest of #866, opened for comparison and not meant to merge as is. The other is #905, which masks the same values with no setting.

Summary

  • Mask send-keys text and set-buffer data in the logged tmux command line by default.
  • Add libtmux.common.set_argv_redactor() to replace the function that decides what is logged.
  • Add two ready-made redactors: redact_argv() (the default) and redact_env_values() (environment values only).

Part of #866, on top of the merged #898. This branch includes #905's change plus the setting.

Usage

from libtmux.common import redact_env_values, set_argv_redactor

set_argv_redactor(redact_env_values)

Passing None restores the default, and list logs the command line unmasked.

Trade-offs

  • Safe by default, and an application that needs to see typed keys can opt back in.
  • Adds three public names, so it needs a minor release.
  • The setting is process-wide. Two libraries in one process cannot choose differently.
  • It follows the shape of the local argv-redaction branch, which made send-keys masking opt-in; here it is on by default.

Test plan

  • test_set_argv_redactor_replaces_and_restores_the_default: with the environment-only redactor typed keys are logged and the token is not; after None typed keys are masked again. It failed on the missing name before the change
  • test_logged_command_line_masks_keys_and_buffer_data: the default masks both values
  • Doctests for the three public functions
  • Full suite on tmux 3.8a
  • ruff check, ruff format --check, mypy, just build-docs
  • Full tmux matrix in CI

@tony tony added example Illustrates an approach; not meant to merge as is alternative Alternative implementation of something another PR already covers labels Nov 21, 2026
tony added a commit that referenced this pull request Nov 21, 2026
why: The two entries named the neighbouring example pull request.

what:
- Cite #906 for the masking and redactor-setting entries
@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.41176% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.81%. Comparing base (97ea2fe) to head (09ddf89).

Files with missing lines Patch % Lines
src/libtmux/common.py 79.41% 6 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #906      +/-   ##
==========================================
+ Coverage   57.66%   57.81%   +0.15%     
==========================================
  Files          29       29              
  Lines        4360     4393      +33     
  Branches      882      890       +8     
==========================================
+ Hits         2514     2540      +26     
- Misses       1536     1542       +6     
- Partials      310      311       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tony
tony force-pushed the example/866-mask-all-opt-out branch 2 times, most recently from 1d37f7b to 112dcae Compare November 21, 2026 22:09
@tony tony mentioned this pull request Nov 21, 2026
32 of 57 tasks
tony added a commit that referenced this pull request Nov 21, 2026
why: libtmux logs the full tmux command line on every DEBUG record and
on errors, including the values of -e NAME=value and set-environment.
The logging conventions already say to log environment variable names
only. Typed keys and buffer data are left visible; masking them is a
separate decision with two example PRs, #905 and #906. Part of #866.

what:
- Mask the value of -e NAME=value on the commands that take it, and the
  value of set-environment, in the logged command line; keep the
  variable names
- Leave the command tmux runs unchanged
- Test that names are logged, values are not, and tmux still stores the
  real value
- Note the masking in the logging conventions, and record the fix under
  Fixes in CHANGES
@tony
tony force-pushed the example/866-mask-all-opt-out branch 5 times, most recently from a18c214 to 38195da Compare November 23, 2026 02:55
@tony

tony commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Side-by-side of #905 and #906, the two alternatives for the rest of #866 (after #898 masked environment values). Both are rebased onto master; the only conflict was CHANGES.

What both do, from the same first commit:

  • Log *** in place of the keys passed to send-keys and the data passed to set-buffer, as common(fix[logging]): Mask environment values in logged argv #898 already does for -e NAME=value.
  • Keep flags, targets and buffer names readable, and leave the command tmux runs unchanged.
  • Add the private _redact_payloads() in libtmux.common.

#905, mask with no setting:

  • 95 lines over 4 files (common.py +58).
  • No new public names.
  • A log can no longer show what was typed into a pane, and nothing brings it back. The CHANGES entry says so under Breaking changes.

#906, mask by default, with a process-wide setting:

  • 196 lines over 4 files (common.py +120).
  • Adds three public names in libtmux.common: set_argv_redactor(), redact_argv() (the default) and redact_env_values() (common(fix[logging]): Mask environment values in logged argv #898's behaviour).
  • set_argv_redactor(redact_env_values) logs typed keys again, set_argv_redactor(list) logs the command line unmasked, and None restores the default.
  • The setting is a module global (_argv_redactor), so it applies to every Server in the process, and the three names become API to keep stable.

The decision: whether logging typed keys needs an escape hatch (#906) or masking is unconditional (#905). Both keep needs-decision until that is chosen; neither is meant to merge as is.

@tony tony added the needs-decision The maintainer chooses before any code label Nov 23, 2026
@tony tony added the area: logging Logging and redaction label Nov 24, 2026
tony added 3 commits November 23, 2026 19:43
why: The logged tmux command line showed send-keys text and set-buffer
data, so a password typed into a pane or copied into a buffer reached
any DEBUG log handler.

what:
- Mask the key arguments of send-keys and the data argument of
  set-buffer in the logged command line; keep flags, targets, buffer
  names and send-keys -X copy-mode commands
- Test that neither value is logged and tmux still stores the buffer
- Note the masking in the logging conventions
why: Masking typed keys and buffer data by default hides what most
readers of DEBUG logs look for, so an application needs a way to log
them again, or to mask more.

what:
- Add set_argv_redactor() to replace the function that turns a tmux
  argument vector into the one that is logged; None restores the
  default
- Add redact_argv() (the default) and redact_env_values() (environment
  values only) as ready-made redactors
- Test replacing and restoring the redactor
- Describe the setting in the logging conventions
why: Logged tmux command lines mask typed keys and buffer data by
default, and callers can change that.

what:
- Add a Breaking changes entry for what logs now mask, with the
  migration
- Add a What's new entry for set_argv_redactor and the ready-made
  redactors
@tony
tony force-pushed the example/866-mask-all-opt-out branch from 38195da to 09ddf89 Compare November 24, 2026 01:48

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

alternative Alternative implementation of something another PR already covers area: logging Logging and redaction example Illustrates an approach; not meant to merge as is needs-decision The maintainer chooses before any code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant