Skip to content

Commit f7c9899

Browse files
committed
PS: Add documentation.
1 parent 2731983 commit f7c9899

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<overview>
6+
<p>The command <code>Set-ExecutionPolicy</code> is used to set the execution policies for Windows computers.
7+
The execution policy is used to determine which configuration files can be loaded and which scripts can be run.
8+
Setting the execution policy to <code>Bypass</code> disables all warnings and signature checks for script execution,
9+
allowing any script—including malicious or unsigned code—to run without restriction.</p>
10+
</overview>
11+
12+
<recommendation>
13+
<p>Always prefer <code>AllSigned</code> to enforce full signature verification.</p>
14+
<p>If this is not possible, set the execution policy to <code>RemoteSigned</code> to allow local scripts while requiring downloaded scripts to be signed.</p>
15+
<p>Always limit the scope of the execution policy by supplying the most restrictive <code>Scope</code> as possible. Use <code>Process</code> to limit the execution policy to the current PowerShell session. When no <code>Scope</code> is supplied the execution policy change is applied system-wide.
16+
</recommendation>
17+
18+
<example>
19+
<p>In the following example, <code>Set-ExecutionPolicy</code> is called twice</p>
20+
21+
<p>The first call sets the execution policy to <code>Bypass</code> which allows any script to be run.</p>
22+
23+
<p>The second call sets the execution policy to <code>RemoteSigned</code> which allows local scripts to be run,
24+
but requires scripts and configurations downloaded from the Internet to be signed.</p>
25+
26+
<sample src="examples/InsecureExecutionPolicy.ps1" />
27+
</example>
28+
29+
<references>
30+
<li>MSDN: <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy">Set-ExecutionPolicy</a>.</li>
31+
</references>
32+
</qhelp>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Invoke-WebRequest -Uri "https://example.com/script.ps1" -OutFile "C:\Path\To\script.ps1"
2+
3+
# BAD: No warnings or prompts when running potentially unsafe scripts
4+
Set-ExecutionPolicy Bypass
5+
& "C:\Path\To\script.ps1" # Will never be blocked
6+
7+
# GOOD: Requires that scripts and configuration files downloaded from the Internet are signed
8+
Set-ExecutionPolicy RemoteSigned
9+
& "C:\Path\To\script.ps1" # Will not run unless script.ps1 is signed

0 commit comments

Comments
 (0)