Skip to content

πŸ› fix(config): mask secrets in parser errors - #4507

Merged
gaborbernat merged 4 commits into
tox-dev:mainfrom
gaborbernat:sec/argparse-redact
Nov 30, 2026
Merged

gaborbernat merged 4 commits into
tox-dev:mainfrom
gaborbernat:sec/argparse-redact

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

When tox rejected a command line argument, the error quoted that argument as typed, including the password in a URL such as https://user:password@host. A CI job that builds a --force-dep requirement from a credentialed URL plus a free-text value someone else controls, such as a release label containing a space, printed its credential to the job log, while the same URL in command displays has been masked since #4334. πŸ” Once this merges, rejected arguments get the same masking in errors. This addresses draft advisory GHSA-25fg-rr6h-j853.

mkdir demo && cd demo
tox --colored no -e py --force-dep 'demo @ https://ci:s3cret@pkgs.example.com/demo-1.2 rc.whl'

Output before (-) and after (+) this change:

-tox legacy: error: argument --force-dep: invalid Requirement value: 'demo @ https://ci:s3cret@pkgs.example.com/demo-1.2 rc.whl'
+tox legacy: error: argument --force-dep: invalid Requirement value: 'demo @ https://*********@pkgs.example.com/demo-1.2 rc.whl'

tox's command line parser, which every subcommand inherits, now masks the message of each argparse error before printing it, using the rules tox already applies to command displays: URL user and password, and the value of a secret-looking --name=value flag. argparse quotes the rejected value with repr, so a line break or tab before such a flag reaches the message as \n or \t; the flag rule treats those escapes as whitespace too. The error for unrecognized arguments keeps masking each argument on its own, so a masked flag value does not swallow the hint printed after it.

Invalid requirements, invalid choices such as --colored, ambiguous option prefixes and -x overrides without = now show * in place of credentials; the exit code and the rest of each message stay the same. The space-separated --name value form stays outside the flag rule, as the logging docs describe.

Reported by oss-scanner: ANT-2026-CJO3IQIA.

argparse quotes the rejected argument as given in its errors, so an invalid
--force-dep requirement, --colored choice or -x override printed URL
credentials that tox masks in command displays and TOX_ warnings.

Every argparse error now goes through the masking used for command displays.
The unrecognized arguments error still masks each argument on its own,
since masking the joined message would hide the hint after a secret inline
flag.
@gaborbernat gaborbernat added bug A confirmed defect security A confirmed security vulnerability labels Nov 30, 2026
argparse quotes a rejected value with repr, which turns a line break or tab
into a backslash escape. The inline flag rule needed real whitespace before
the dash, so --colored 'a<newline>--token=x' still printed the token.

The rule now also accepts the repr escape of each whitespace character before
the dash. Masking the message after argparse builds it keeps the fix out of
argparse internals, at the cost of masking a literal backslash-n before a
secret-looking flag in command displays.
@gaborbernat
gaborbernat merged commit 069189d into tox-dev:main Nov 30, 2026
10 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug A confirmed defect security A confirmed security vulnerability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant