Skip to content

Update MaxVisitCount and MaxHashtableKeyCount if VisitorSafeValueContext indicates SkipLimitCheck is true#27306

Merged
TravisEz13 merged 1 commit intoPowerShell:masterfrom
SeeminglyScience:forward-port-38918
Apr 20, 2026
Merged

Update MaxVisitCount and MaxHashtableKeyCount if VisitorSafeValueContext indicates SkipLimitCheck is true#27306
TravisEz13 merged 1 commit intoPowerShell:masterfrom
SeeminglyScience:forward-port-38918

Conversation

@SeeminglyScience
Copy link
Copy Markdown
Contributor

@SeeminglyScience SeeminglyScience commented Apr 20, 2026

PR Summary

Looks like I cherry picked a different porting and it erased the correct attribution, credit to @anamnavi for the fix.

PR Context

PR Checklist

… `VisitorSafeValueContext` indicates `SkipLimitCheck` is true

Update MaxVisitCount and MaxHashtableKeyCount if visitor safe value context indicates SkipLimitCheck is true

Related work items: #163537

----
#### AI description  (iteration 1)
#### PR Classification
Enhancement: Conditionally update AST limit checks based on safe value context flags.

#### PR Summary
This pull request refactors the safe value visitor to initialize runtime limit values, setting them to maximum if the `SkipLimitCheck` flag is present, and adjusts the corresponding condition checks to support larger AST structures safely.
- `src/System.Management.Automation/engine/parser/SafeValues.cs`: Replaced hard-coded limit constants with runtime-initialized readonly fields based on the safe value context, and updated conditional checks in `IsAstSafe` and `VisitHashtable`.
- `test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1`: Added tests to validate behavior when using `-SkipLimitCheck`, ensuring insecure PSD1 files are properly rejected.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->

Related work items: #163537
Copilot AI review requested due to automatic review settings April 20, 2026 17:10
@SeeminglyScience SeeminglyScience added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Apr 20, 2026
@SeeminglyScience SeeminglyScience requested a review from a team as a code owner April 20, 2026 17:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates PowerShell’s “safe value” AST validation so that when Import-PowerShellDataFile -SkipLimitCheck is used, the size limits are relaxed without bypassing the security validation that prevents unsafe expressions from being evaluated.

Changes:

  • Make IsSafeValueVisitor apply dynamic max visit/key-count limits based on SafeValueContext (instead of always using constants).
  • Remove the SkipHashtableSizeCheck fast-path that previously bypassed IsAstSafe entirely.
  • Add a regression test ensuring insecure PSD1 content still fails when -SkipLimitCheck is used.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/System.Management.Automation/engine/parser/SafeValues.cs Ensures “skip limit” relaxes size limits via visitor configuration while still enforcing AST safety checks.
test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1 Adds coverage for insecure PSD1 input with -SkipLimitCheck.

Comment thread src/System.Management.Automation/engine/parser/SafeValues.cs
@TravisEz13 TravisEz13 merged commit e2784b8 into PowerShell:master Apr 20, 2026
45 checks passed
@SeeminglyScience SeeminglyScience deleted the forward-port-38918 branch April 20, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport-7.4.x-Done Backport-7.5.x-Done Backport-7.6.x-Done CL-Engine Indicates that a PR should be marked as an engine change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants