|
| 1 | +--- |
| 2 | +name: powershell-security-review |
| 3 | +description: Review PowerShell code for security problems such as exposed secrets, unsafe credential handling, command or path injection, and disabled certificate checks. Use when asked for a security review or audit of PowerShell code. |
| 4 | +--- |
| 5 | + |
| 6 | +# Security review of PowerShell code |
| 7 | + |
| 8 | +Read `.github/instructions/powershell-security.instructions.md` first, unless it is already loaded. |
| 9 | + |
| 10 | +## Steps |
| 11 | + |
| 12 | +1. Map where data enters the code: parameters, files, environment variables, web responses, and |
| 13 | + pipeline input. Treat each as untrusted unless the code proves otherwise. |
| 14 | +2. Follow each input to where it is used and check: |
| 15 | + - Secrets and credentials: SEC-01 to SEC-08, and SEC-50 to SEC-53 where the code uses a secret |
| 16 | + vault. Search for literals that look like passwords, tokens, keys, and connection strings, |
| 17 | + including in comments, defaults, and test data. |
| 18 | + - Command construction: SEC-10. Look for `Invoke-Expression`, `[scriptblock]::Create()`, |
| 19 | + `Start-Process` with a built argument string, and strings passed to `cmd /c` or `pwsh -Command`. |
| 20 | + - Paths: SEC-12. Look for input joined into a path that is then read, written, or deleted. |
| 21 | + - Queries: SEC-13. |
| 22 | + - Input checks: SEC-11 and SEC-16 to SEC-19. |
| 23 | + - Code signing, where the code signs files: SEC-30 to SEC-35. |
| 24 | + - Transport and privilege: SEC-14 and SEC-15. |
| 25 | +3. Check what the code writes. Verbose, debug, warning, and error messages, log files, and exported |
| 26 | + files must not contain secrets or personal data. |
| 27 | +4. Run PSScriptAnalyzer. Its rules `PSAvoidUsingPlainTextForPassword`, |
| 28 | + `PSAvoidUsingConvertToSecureStringWithPlainText`, `PSAvoidUsingUsernameAndPasswordParams`, and |
| 29 | + `PSAvoidUsingInvokeExpression` cover part of this. |
| 30 | +5. Confirm each finding by reading the full path from input to use. A pattern match alone is not a |
| 31 | + finding. The patterns of SEC-40 find candidates. `Add-Type -TypeDefinition` is a Medium finding |
| 32 | + (SEC-41). |
| 33 | + |
| 34 | +## Report |
| 35 | + |
| 36 | +List findings with the most serious first, each with its tier (Critical, High, Medium, or Low), and |
| 37 | +state the overall risk as the highest tier found (SEC-42): file and line, rule ID, how the problem |
| 38 | +could be exploited or exposed, and the corrected code. Say which inputs you traced and which you did |
| 39 | +not. If you find a real secret, tell the user that it must be revoked and replaced; removing it from |
| 40 | +the file does not remove it from the repository history. This review covers the code only. It is not |
| 41 | +a compliance assessment, so do not state that the code meets any regulation or framework. |
0 commit comments