Skip to content

Commit 28de6ed

Browse files
committed
PS: Also require '-Force' with a truthy value. Note the 'NOT DETECTED' test. We will fix that in the next commit.
1 parent 4e524a1 commit 28de6ed

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

powershell/ql/src/queries/security/cwe-250/InsecureExecutionPolicy.ql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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

4649
class Process extends Expr {
@@ -56,5 +59,7 @@ class BypassSetExecutionPolicy extends SetExecutionPolicy {
5659
}
5760

5861
from BypassSetExecutionPolicy setExecutionPolicy
59-
where not setExecutionPolicy.getScope() instanceof Process
62+
where
63+
not setExecutionPolicy.getScope() instanceof Process and
64+
setExecutionPolicy.isForced()
6065
select setExecutionPolicy, "Insecure use of 'Set-ExecutionPolicy'."
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
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'. |
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
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
211
Set-ExecutionPolicy RemoteSigned # GOOD
312
Set-ExecutionPolicy Bypass -Scope Process # GOOD
413
Set-ExecutionPolicy RemoteSigned -Scope Process # GOOD
5-
Set-ExecutionPolicy Bypass -Scope MachinePolicy # BAD
14+
Set-ExecutionPolicy Bypass -Scope MachinePolicy # GOOD

0 commit comments

Comments
 (0)