Skip to content

[codex] Reject unlowered PowerShell AST regions - #24092

Merged
viyatb-oai merged 5 commits into
mainfrom
dev/bookholt/reject-powershell-param-blocks
Jun 23, 2026
Merged

[codex] Reject unlowered PowerShell AST regions#24092
viyatb-oai merged 5 commits into
mainfrom
dev/bookholt/reject-powershell-param-blocks

Conversation

@bookholt-oai

@bookholt-oai bookholt-oai commented May 22, 2026

Copy link
Copy Markdown
Contributor

Why

On Windows, Codex uses a PowerShell safe-command classifier to decide whether a command is read-only enough to run without additional approval. The classifier lowers EndBlock.Statements into argv-like command words and checks those words against a safelist.

PowerShell can execute code stored elsewhere in the AST. Parameter defaults, named blocks, using preambles, and top-level trap handlers are not represented in the lowered statement list. Ignoring those regions can make a side-effecting script look like a read-only command.

What

Fail closed whenever a PowerShell script contains executable AST content that the current lowering does not represent.

How

  • Return unsupported for parameter, dynamic-parameter, begin, process, and clean blocks.
  • Return unsupported for using module and using assembly preambles.
  • Return unsupported for non-empty EndBlock.Traps collections.
  • Preserve compatibility with Windows PowerShell 5.1 by looking up CleanBlock dynamically.
  • Treat unsupported as a failure to prove that the command is safe, routing it through the normal approval path.
  • Add parser-level and end-to-end regressions for parameter blocks, named blocks, using statements, and trap handlers.

This does not make these PowerShell forms invalid or prevent them from running. It prevents automatic safe-command approval when the classifier cannot account for all executable behavior.

Testing

  • just test -p codex-shell-command
  • Windows CI exercises the parser and end-to-end safe-command regressions against a real PowerShell installation.

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 14 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this Jun 6, 2026
@bookholt-oai bookholt-oai reopened this Jun 9, 2026
@bookholt-oai
bookholt-oai force-pushed the dev/bookholt/reject-powershell-param-blocks branch from a68d68e to c8674c3 Compare June 9, 2026 22:03
@bookholt-oai
bookholt-oai marked this pull request as ready for review June 9, 2026 22:19
Comment thread codex-rs/shell-command/src/command_safety/powershell_parser.ps1 Outdated
@bookholt-oai bookholt-oai changed the title [codex] Reject PowerShell param blocks in safe-command parsing [codex] Reject unlowered PowerShell AST regions Jun 18, 2026

@viyatb-oai viyatb-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed head 0726c1c. The original unlowered PowerShell AST findings are addressed, including named blocks, using preambles, and trap handlers, with parser and end-to-end regression coverage.

@viyatb-oai
viyatb-oai enabled auto-merge (squash) June 22, 2026 23:15
@viyatb-oai
viyatb-oai merged commit 27f22b5 into main Jun 23, 2026
46 of 47 checks passed
@viyatb-oai
viyatb-oai deleted the dev/bookholt/reject-powershell-param-blocks branch June 23, 2026 03:09
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants