MCPcopy Create free account
hub / github.com/freecodexyz/free-code / checkModuleLoading

Function checkModuleLoading

src/tools/PowerShellTool/powershellSecurity.ts:946–960  ·  view source on GitHub ↗

* 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,
)

Source from the content-addressed store, hash-verified

944 */
945
946function 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

Callers

nothing calls this directly

Calls 2

getAllCommandsFunction · 0.50
hasMethod · 0.45

Tested by

no test coverage detected