Skip to content

πŸ› fix(redact): mask URL passwords fused into the program - #4508

Merged
gaborbernat merged 5 commits into
tox-dev:mainfrom
gaborbernat:sec/shell-cmd-redact
Nov 30, 2026
Merged

gaborbernat merged 5 commits into
tox-dev:mainfrom
gaborbernat:sec/shell-cmd-redact

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

When the folder tox runs in has an unbalanced quote in its name (Bob's proj, or a CI checkout named after a branch such as it's-fixed), tox keeps an INI command that starts with that folder as one argument. πŸ” tox then printed any URL password on that line in the command echo and in the .tox/<env>/log files, so anyone reading the CI console or the uploaded logs saw it, although the usage guide says tox masks URL user info in command displays. Once this merges, those outputs mask it too. This addresses draft advisory GHSA-rpq3-qxcr-j53q.

$ mkdir -p "it's-mine/ci" && cd "it's-mine"
$ printf '#!/bin/sh\n' > ci/migrate.sh && chmod +x ci/migrate.sh
$ cat > tox.ini <<'EOF'
[testenv:migrate]
skip_install = true
allowlist_externals = */ci/migrate.sh
commands = {env:PWD}/ci/migrate.sh --database=postgresql://app:{env:DB_PASSWORD}@db.example/app
EOF
$ DB_PASSWORD=s3cr3t tox run -e migrate | grep 'commands\[0\]>'; grep '^cmd:' .tox/migrate/log/*.log

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

-migrate: commands[0]> 'ci/migrate.sh --database=postgresql:/app:s3cr3t@db.example/app'
-cmd: 'ci/migrate.sh --database=postgresql:/app:s3cr3t@db.example/app'
+migrate: commands[0]> 'ci/migrate.sh --database=postgresql:/**********@db.example/app'
+cmd: 'ci/migrate.sh --database=postgresql:/**********@db.example/app'

The command display shortens a program inside the working folder to a relative path, and Python's pathlib collapses the double slash of postgresql:// while doing so. The URL masking from #4334 only recognizes scheme://, so it missed the shortened text. The display now masks the program before shortening it, then masks the whole command again as before, which still catches a secret flag that follows the folder path.

The command echo, the per-command log, the exit N line and the commands_retry warning now mask the password, on Linux and Windows alike. The command itself still fails to start, because the unbalanced quote breaks the INI command line, and the masked URL keeps the single slash. Quoting the program in tox.ini or using a TOML array avoids the fused argument altogether.

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

An unbalanced quote in the checkout path makes tox keep the rest of an INI
command line as one argument, so a later URL lands inside the program. tox
shortens a program below the working directory to a relative path, and
pathlib collapses the URL's scheme:// to scheme:/, which the URL rule does not
match. The command echo, the per-command log and the retry warning then
printed the password.

Mask the program before shortening it as well. The pass after shortening
stays, because it catches a secret flag that sits right after the working
directory.
@gaborbernat gaborbernat added bug A confirmed defect security A confirmed security vulnerability labels Nov 30, 2026
pre-commit-ci Bot and others added 4 commits November 30, 2026 01:59
The flag-after-cwd case passed on the merge base: the redaction after
relative_to already masked --token=hunter2. Only the URL userinfo case fails
without the fix, so it is the one test kept.
@gaborbernat
gaborbernat merged commit 0bb702e 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