Skip to content

Protect ForEach() property assignment on non-core types in Constrained Language Mode - #28207

Open
Justin Chung (jshigetomi) wants to merge 2 commits into
masterfrom
170
Open

Justin Chung (jshigetomi) wants to merge 2 commits into
masterfrom
170

Conversation

@jshigetomi

Copy link
Copy Markdown
Collaborator

PR Summary

This pull request strengthens the security enforcement for property setting via the ForEach engine intrinsic method in Constrained Language mode and adds corresponding tests to verify the behavior. The main change is to prevent property assignment on non-core types when PowerShell is running in Constrained Language mode, except when the system is only auditing (not enforcing) the policy.

PR Context

PR Checklist

Copilot AI balanced review requested due to automatic review settings October 14, 2026 18:16
@jshigetomi
Justin Chung (jshigetomi) requested a review from a team as a code owner October 14, 2026 18:16
@jshigetomi Justin Chung (jshigetomi) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Oct 14, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human security review remains necessary for enforcement and audit behavior, with an unresolved compatibility regression.

1 open finding
What changed in this PR

Strengthens Constrained Language enforcement for property assignments through PowerShell’s intrinsic ForEach method.

Changes:

  • Rejects non-core property assignments while allowing audit-only execution with logging.
  • Adds tests for rejected non-core setters and permitted core-type setters.
File Description
test/​powershell/​Modules/​Microsoft.PowerShell.Security/​ConstrainedLanguageRestriction.Tests.ps1 Adds property-assignment restriction tests.
src/​System.Management.Automation/​engine/​runtime/​Operations/​MiscOps.cs Adds setter enforcement and audit logging.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

var property = member as PSPropertyInfo;
if (languageMode == PSLanguageMode.ConstrainedLanguage
&& numArgs != 0
&& !CoreTypes.Contains(basedCurrent.GetType()))
@jshigetomi Justin Chung (jshigetomi) changed the title Throw in ForEach method if setting property in CLM Restrict ForEach() property assignment on non-core types in Constrained Language Mode Oct 14, 2026
@jshigetomi Justin Chung (jshigetomi) changed the title Restrict ForEach() property assignment on non-core types in Constrained Language Mode Protect ForEach() property assignment on non-core types in Constrained Language Mode Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants