File tree Expand file tree Collapse file tree 3 files changed +19
-5
lines changed
src/queries/security/cwe-250
test/query-tests/security/cwe-250 Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,9 @@ class SetExecutionPolicy extends CmdCall {
4141 else result = this .getPositionalArgument ( 1 )
4242 )
4343 }
44+
45+ /** Holds if the argument `flag` is supplied with a `$true` value. */
46+ predicate isForced ( ) { this .getNamedArgument ( "force" ) .getValue ( ) .asBoolean ( ) = true }
4447}
4548
4649class Process extends Expr {
@@ -56,5 +59,7 @@ class BypassSetExecutionPolicy extends SetExecutionPolicy {
5659}
5760
5861from BypassSetExecutionPolicy setExecutionPolicy
59- where not setExecutionPolicy .getScope ( ) instanceof Process
62+ where
63+ not setExecutionPolicy .getScope ( ) instanceof Process and
64+ setExecutionPolicy .isForced ( )
6065select setExecutionPolicy , "Insecure use of 'Set-ExecutionPolicy'."
Original file line number Diff line number Diff line change 1- | test.ps1:1:1:1:26 | Call to set-executionpolicy | Insecure use of 'Set-ExecutionPolicy'. |
2- | test.ps1:5:1:5:47 | Call to set-executionpolicy | Insecure use of 'Set-ExecutionPolicy'. |
1+ | test.ps1:1:1:1:33 | Call to set-executionpolicy | Insecure use of 'Set-ExecutionPolicy'. |
2+ | test.ps1:5:1:5:54 | Call to set-executionpolicy | Insecure use of 'Set-ExecutionPolicy'. |
Original file line number Diff line number Diff line change 1- Set-ExecutionPolicy Bypass # BAD
1+ Set-ExecutionPolicy Bypass - Force # BAD
2+ Set-ExecutionPolicy RemoteSigned - Force # GOOD
3+ Set-ExecutionPolicy Bypass - Scope Process - Force # GOOD
4+ Set-ExecutionPolicy RemoteSigned - Scope Process - Force # GOOD
5+ Set-ExecutionPolicy Bypass - Scope MachinePolicy - Force # BAD
6+
7+ Set-ExecutionPolicy Bypass - Force:$true # BAD [NOT DETECTED]
8+ Set-ExecutionPolicy Bypass - Force:$false # GOOD
9+
10+ Set-ExecutionPolicy Bypass # GOOD
211Set-ExecutionPolicy RemoteSigned # GOOD
312Set-ExecutionPolicy Bypass - Scope Process # GOOD
413Set-ExecutionPolicy RemoteSigned - Scope Process # GOOD
5- Set-ExecutionPolicy Bypass - Scope MachinePolicy # BAD
14+ Set-ExecutionPolicy Bypass - Scope MachinePolicy # GOOD
You can’t perform that action at this time.
0 commit comments