* 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, )
| 141 | * entirely, valid=false already returns 'ask' earlier in the chain). |
| 142 | */ |
| 143 | function 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. |
nothing calls this directly
no test coverage detected