Skip to content

fix(security): command injection via az aks command invoke - #560

Merged
Suneha Bose (bosesuneha) merged 1 commit into
Azure:mainfrom
davidgamero:sanitize-private-cluster-command
Aug 26, 2026
Merged

fix(security): command injection via az aks command invoke#560
Suneha Bose (bosesuneha) merged 1 commit into
Azure:mainfrom
davidgamero:sanitize-private-cluster-command

Conversation

@davidgamero

Copy link
Copy Markdown
Collaborator

PrivateKubectl.execute flattened its argv array with args.join(' ') and passed the result to az aks command invoke --command.

The run-command pod uses its own high-privilege service account, so this escapes whatever RBAC the workflow's kubeconfig was scoped to.

Values reaching the command string:

  • manifest metadata.name, via the temp filename passed to -f. getNewTempManifestFileName applies path.basename(), which strips path separators but not ';', '|', '$(...)', backticks or spaces.
  • the namespace input, via --namespace. Workflows commonly build this from github.head_ref, and git permits ';', '$', '(', ')', '`', '|' and '&' in branch names.
  • the workflow annotation payload, which is unescaped JSON containing spaces and double quotes plus GITHUB_WORKFLOW and the branch name.

Fix: rewrite filename arguments positionally on the argv array, then POSIX-quote every element before joining. Quoting is only possible once the filename rewriting no longer needs to re-parse a flattened string, so the two changes are inseparable.

This also removes the minimist re-parse and the '-f ' substring test, which mis-handled any value containing a space and could rewrite unrelated arguments.

Also honours the caller's silent flag: command output was previously written to the debug log unconditionally, including for callers such as getAllPods() that explicitly request silence.

Tests verify the fix by executing the generated command in a real POSIX shell with kubectl stubbed to dump its argv, then asserting it reconstructs the original array exactly, for payloads carried in annotations, resource names, namespaces and filenames.

Also removes minimist as it's unused dependency

@davidgamero
David Gamero (davidgamero) requested a review from a team as a code owner August 26, 2026 14:44
@davidgamero David Gamero (davidgamero) changed the title fix(security): command injection via az aks command invoke (CWE-78) fix(security): command injection via az aks command invoke Aug 26, 2026
@davidgamero
David Gamero (davidgamero) force-pushed the sanitize-private-cluster-command branch from 2afa703 to 41f4b65 Compare August 26, 2026 14:45
@davidgamero
David Gamero (davidgamero) force-pushed the sanitize-private-cluster-command branch from 41f4b65 to 51dc0ee Compare August 26, 2026 14:45

@bosesuneha Suneha Bose (bosesuneha) 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.

lgtm

@bosesuneha
Suneha Bose (bosesuneha) merged commit 0fc36d5 into Azure:main Aug 26, 2026
13 checks passed
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.

2 participants