GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Disable the debugger when in system lock-down mode (#9645) · PowerShell/PowerShell@bb726da

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/System.Management.Automation/engine/debugger
    • debugger.cs
  • test/powershell/Modules/Microsoft.PowerShell.Security
    • ConstrainedLanguageDebugger.Tests.ps1
    • ConstrainedLanguageRestriction.Tests.ps1
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/System.Management.Automation/engine/debugger/debugger.cs‎

Copy file name to clipboardExpand all lines: src/System.Management.Automation/engine/debugger/debugger.cs
+46-6Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,12 +1132,16 @@ private Breakpoint AddCommandBreakpoint(CommandBreakpoint breakpoint)
11321132
internal Breakpoint NewCommandBreakpoint(string path, string command, ScriptBlock action)
11331133
{
11341134
WildcardPattern pattern = WildcardPattern.Get(command, WildcardOptions.Compiled | WildcardOptions.IgnoreCase);
1135+
1136+
CheckForBreakpointSupport();
11351137
return AddCommandBreakpoint(new CommandBreakpoint(path, pattern, command, action));
11361138
}
11371139

11381140
internal Breakpoint NewCommandBreakpoint(string command, ScriptBlock action)
11391141
{
11401142
WildcardPattern pattern = WildcardPattern.Get(command, WildcardOptions.Compiled | WildcardOptions.IgnoreCase);
1143+
1144+
CheckForBreakpointSupport();
11411145
return AddCommandBreakpoint(new CommandBreakpoint(null, pattern, command, action));
11421146
}
11431147

@@ -1175,13 +1179,15 @@ internal Breakpoint NewLineBreakpoint(string path, int line, ScriptBlock action)
11751179
{
11761180
Diagnostics.Assert(path != null, "caller to verify path is not null");
11771181

1182+
CheckForBreakpointSupport();
11781183
return AddLineBreakpoint(new LineBreakpoint(path, line, action));
11791184
}
11801185

11811186
internal Breakpoint NewStatementBreakpoint(string path, int line, int column, ScriptBlock action)
11821187
{
11831188
Diagnostics.Assert(path != null, "caller to verify path is not null");
11841189

1190+
CheckForBreakpointSupport();
11851191
return AddLineBreakpoint(new LineBreakpoint(path, line, column, action));
11861192
}
11871193

@@ -1201,11 +1207,13 @@ internal VariableBreakpoint AddVariableBreakpoint(VariableBreakpoint breakpoint)
12011207

12021208
internal Breakpoint NewVariableBreakpoint(string path, string variableName, VariableAccessMode accessMode, ScriptBlock action)
12031209
{
1210+
CheckForBreakpointSupport();
12041211
return AddVariableBreakpoint(new VariableBreakpoint(path, variableName, accessMode, action));
12051212
}
12061213

12071214
internal Breakpoint NewVariableBreakpoint(string variableName, VariableAccessMode accessMode, ScriptBlock action)
12081215
{
1216+
CheckForBreakpointSupport();
12091217
return AddVariableBreakpoint(new VariableBreakpoint(null, variableName, accessMode, action));
12101218
}
12111219

@@ -1761,12 +1769,6 @@ private void OnDebuggerStop(InvocationInfo invocationInfo, List<Breakpoint> brea
17611769
originalLanguageMode = _context.LanguageMode;
17621770
_context.LanguageMode = PSLanguageMode.FullLanguage;
17631771
}
1764-
else if (System.Management.Automation.Security.SystemPolicy.GetSystemLockdownPolicy() ==
1765-
System.Management.Automation.Security.SystemEnforcementMode.Enforce)
1766-
{
1767-
// If there is a system lockdown in place, enforce it
1768-
originalLanguageMode = Utils.EnforceSystemLockDownLanguageMode(this._context);
1769-
}
17701772

17711773
// Update the prompt to the debug prompt
17721774
if (hadDefaultPrompt)
@@ -2060,6 +2062,17 @@ private void SetInternalDebugMode(InternalDebugMode mode)
20602062
{
20612063
lock (_syncObject)
20622064
{
2065+
// Disable script debugger when in system lock down mode
2066+
if (IsSystemLockedDown)
2067+
{
2068+
if (_context._debuggingMode != (int)InternalDebugMode.Disabled)
2069+
{
2070+
_context._debuggingMode = (int)InternalDebugMode.Disabled;
2071+
}
2072+
2073+
return;
2074+
}
2075+
20632076
switch (mode)
20642077
{
20652078
case InternalDebugMode.InPushedStop:
@@ -2086,6 +2099,24 @@ private bool CanEnableDebugger
20862099
}
20872100
}
20882101

2102+
private static bool IsSystemLockedDown
2103+
{
2104+
get
2105+
{
2106+
return (System.Management.Automation.Security.SystemPolicy.GetSystemLockdownPolicy() ==
2107+
System.Management.Automation.Security.SystemEnforcementMode.Enforce);
2108+
}
2109+
}
2110+
2111+
private static void CheckForBreakpointSupport()
2112+
{
2113+
if (IsSystemLockedDown)
2114+
{
2115+
// Local script debugging is not supported in locked down mode
2116+
throw new PSNotSupportedException();
2117+
}
2118+
}
2119+
20892120
#region Enable debug stepping
20902121

20912122
[Flags]
@@ -2323,6 +2354,15 @@ public override void SetDebugMode(DebugModes mode)
23232354
{
23242355
lock (_syncObject)
23252356
{
2357+
// Restrict local script debugger mode when in system lock down.
2358+
// DebugModes enum flags provide a combination of values. To disable local script debugging
2359+
// we have to disallow 'LocalScript' and 'Default' flags and only allow 'None' or 'RemoteScript'
2360+
// flags exclusively. This allows only no debugging 'None' or remote debugging 'RemoteScript'.
2361+
if (IsSystemLockedDown && (mode != DebugModes.None) && (mode != DebugModes.RemoteScript))
2362+
{
2363+
mode = DebugModes.RemoteScript;
2364+
}
2365+
23262366
base.SetDebugMode(mode);
23272367

23282368
if (!CanEnableDebugger)

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.