Repository navigation
Add additional language mode checks to PSSetMemberBinder (#202) - #28215
Open
Aditya Patwardhan (adityapatwardhan) wants to merge 1 commit into
Open
Aditya Patwardhan (adityapatwardhan) wants to merge 1 commit into
Aditya Patwardhan (adityapatwardhan) wants to merge 1 commit into
Conversation
Aditya Patwardhan (adityapatwardhan)
requested review from
a team,
Patrick Meinecke (SeeminglyScience) and
Dongbo Wang (daxian-dbw)
as code owners
October 14, 2026 23:03
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Security-boundary enforcement and audit behavior need human validation, with positive coverage still needed for permitted assignments.
1 open finding
What changed in this PR
Strengthens Constrained Language Mode enforcement for member assignments in PowerShell’s dynamic binder.
Changes:
- Centralizes instance-member checks and updates enforcement and audit handling.
- Adds cached reflection metadata for the helper.
- Adds rejection tests for script and alias properties.
| File | Description |
|---|---|
| test/powershell/Modules/Microsoft.PowerShell.Security/ConstrainedLanguageRestriction.Tests.ps1 | Tests restricted property assignments. |
| src/System.Management.Automation/engine/runtime/Binding/Binders.cs | Enforces language-mode restrictions during assignment. |
| src/System.Management.Automation/engine/parser/Compiler.cs | Caches reflection metadata for the new helper. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| ExecutionContext context = LocalPipeline.GetExecutionContextFromTLS(); | ||
| // Explicit `GetType() ==` instead of `is` as we only want to allow `PSNoteProperty`, | ||
| // classes that inherits from it should be excluded. | ||
| if ((context != null) && (context.LanguageMode == PSLanguageMode.ConstrainedLanguage) && (memberInfo.GetType() != typeof(PSNoteProperty))) |
Collaborator
|
Dup #28215 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

PR Summary
This pull request enhances the enforcement of PowerShell's Constrained Language Mode (CLM) restrictions on setting instance members, ensuring that only
NotePropertyassignments are allowed and that other property types (likeScriptPropertyandAliasProperty) are properly blocked. It introduces a new helper method to centralize this logic, updates the dynamic binder to use it, and adds targeted tests to verify the behavior.Security enforcement and property assignment logic:
SetInstanceMemberValueinPSSetMemberBinderto enforce CLM restrictions when setting instance member values, allowing onlyNotePropertyassignments and auditing or blocking others as appropriate.FallbackSetMemberto use the newSetInstanceMemberValuemethod, replacing direct property assignments and ensuring consistent enforcement of CLM rules. [1] [2]FallbackSetMemberfor property setting in CLM: now directly checks language mode and type, blocks or audits as needed, and logs audit messages for non-core types when enforcement is set to audit.Reflection and infrastructure:
PSSetMemberBinder.SetInstanceMemberValuemethod inCachedReflectionInfoto support dynamic invocation.Testing:
ScriptPropertyandAliasPropertyinstance members is correctly rejected in Constrained Language Mode, while ensuring language mode is reset after each test.PR Context
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header