* Module-loading cmdlets execute a .psm1's top-level script body (Import-Module) * or download from arbitrary repositories (Install-Module, Save-Module). A * wildcard allow rule like `Import-Module:*` would let an attacker-supplied * .psm1 execute with the user's privileges — same risk as Invoke-
( parsed: ParsedPowerShellCommand, )
| 944 | */ |
| 945 | |
| 946 | function checkModuleLoading( |
| 947 | parsed: ParsedPowerShellCommand, |
| 948 | ): PowerShellSecurityResult { |
| 949 | for (const cmd of getAllCommands(parsed)) { |
| 950 | const lower = cmd.name.toLowerCase() |
| 951 | if (MODULE_LOADING_CMDLETS.has(lower)) { |
| 952 | return { |
| 953 | behavior: 'ask', |
| 954 | message: |
| 955 | 'Command loads, installs, or downloads a PowerShell module or script, which can execute arbitrary code', |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | return { behavior: 'passthrough' } |
| 960 | } |
| 961 | |
| 962 | /** |
| 963 | * Set-Alias/New-Alias can hijack future command resolution: after |
nothing calls this directly
no test coverage detected