Skip to content

fix(shellwrap): mask glued docker env forms inside a command string - #1749

Merged
Dumbris merged 1 commit into
smart-mcp-proxy:mainfrom
rudycelekli:fix/glued-env-redact-20261023-01
Oct 26, 2026
Merged

Dumbris merged 1 commit into
smart-mcp-proxy:mainfrom
rudycelekli:fix/glued-env-redact-20261023-01

Conversation

@rudycelekli

Copy link
Copy Markdown
Contributor

Pull Request

Description

shellwrap.RedactDockerArgs masks the value of every docker env injection in three argv shapes: -e KEY=VALUE, the glued -eKEY=VALUE / --env=KEY=VALUE, and a whitespace-bearing command-string element. But the command-string rule (RedactDockerCommandStringWith) only knows the spaced form — its regex requires whitespace after -e/--env. So the glued spellings are masked when they are separate argv elements and published in the clear once a login-shell wrap folds the docker line into the single -c string.

Trigger. A stdio server configured as

{"command": "docker", "args": ["run", "-i", "--rm", "--env=API_TOKEN=…", "img"]}

is wrapped by WrapWithUserShell into ["-l", "-c", "docker run -i --rm --env=API_TOKEN=… img"]. Every spawn log sink (launcher command prepared, the [launcher] starting: banner in server-<name>.log, Initialized stdio transport) goes through oauth.AuditRedaction.SpawnArgv, whose stage 1 is this structural rule. Stage 2 (flag-name + value-shape) does not rescue it when the key name is not sensitive-looking, which is exactly the case the structural rule exists for. Checked through SpawnArgv on main:

["run" "--env=FOO=hunter2xyz" "img"]              -> ["run" "--env=FOO=••••" "img"]
["-l" "-c" "docker run -e FOO=hunter2xyz img"]    -> ["-l" "-c" "docker run -e FOO=•••• img"]
["-l" "-c" "docker run --env=FOO=hunter2xyz img"] -> ["-l" "-c" "docker run --env=FOO=hunter2xyz img"]
["-l" "-c" "docker run -eFOO=hunter2xyz img"]     -> ["-l" "-c" "docker run -eFOO=hunter2xyz img"]

Fix

A second regex in RedactDockerCommandStringWith covers the glued forms, bare or as one quoted word (Shellescape single-quotes the whole token when the value has whitespace, e.g. '--env=K=a b'). The value goes through the same maskEnvTokenWith, so the key and quotes are kept and only VALUE is masked. It is the same -e + = rule the argv path already applies to a glued element, so the two paths now agree. Tokens without = (node -e console.log(1), --entrypoint /bin/sh) are untouched.

Testing

  • I have tested these changes locally
  • I have added/updated tests that prove my fix is effective or my feature works
  • All existing tests pass

TestRedactDockerCommandString_GluedForms (in internal/shellwrap/redact_test.go) covers long, short, single-quoted and double-quoted glued forms through both RedactDockerCommandString and RedactDockerArgs with a -c element, plus a no-change check for non-env -e… tokens.

go test ./internal/shellwrap -count=1                      # ok
go test ./internal/oauth -count=1                          # ok (SpawnArgv consumer)
# with redact.go reverted:
go test ./internal/shellwrap -run GluedForms -count=1      # FAIL TestRedactDockerCommandString_GluedForms
gofmt -l internal/shellwrap                                # clean

Co-authored-by: Cursor <cursoragent@cursor.com>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/shellwrap/redact.go 87.50% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Dumbris Dumbris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: the PR test fails on main for the reason described and passes on this branch merged with main; race tests for the touched packages and CI lint (bare and server tags) are clean. Also built and tested together with the rest of this batch, independently reviewed, and cross-reviewed with a second model.

@Dumbris
Dumbris merged commit 98e568b into smart-mcp-proxy:main Oct 26, 2026
46 checks passed
@Dumbris

Dumbris commented Oct 26, 2026

Copy link
Copy Markdown
Member

Merged. Thank you, @rudycelekli! Glued docker env forms (--env=K=V, -eK=V) inside a login-shell command string were logged in clear; they are masked now.

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.

3 participants