MCPcopy Create free account
hub / github.com/WJX20/claude-code / checkDynamicCommandName

Function checkDynamicCommandName

src/tools/PowerShellTool/powershellSecurity.ts:143–160  ·  view source on GitHub ↗

* Checks for dynamic command invocation where the command name itself is an * expression that cannot be statically resolved. * * PoCs: * & ${function:Invoke-Expression} 'payload' — VariableExpressionAst * & ('iex','x')[0] 'payload' — IndexExpressionAst → 'Other' * & ('i'

(
  parsed: ParsedPowerShellCommand,
)

Source from the content-addressed store, hash-verified

141 * entirely, valid=false already returns 'ask' earlier in the chain).
142 */
143function checkDynamicCommandName(
144 parsed: ParsedPowerShellCommand,
145): PowerShellSecurityResult {
146 for (const cmd of getAllCommands(parsed)) {
147 if (cmd.elementType !== 'CommandAst') {
148 continue
149 }
150 const nameElementType = cmd.elementTypes?.[0]
151 if (nameElementType !== undefined && nameElementType !== 'StringConstant') {
152 return {
153 behavior: 'ask',
154 message:
155 'Command name is a dynamic expression which cannot be statically validated',
156 }
157 }
158 }
159 return { behavior: 'passthrough' }
160}
161
162/**
163 * Checks for encoded command parameters which obscure intent.

Callers

nothing calls this directly

Calls 1

getAllCommandsFunction · 0.50

Tested by

no test coverage detected