Repository navigation
fix(install): 提前诊断 PowerShell 受限语言模式 - #1536
Open
haofeng0705 wants to merge 3 commits into
Open
haofeng0705 wants to merge 3 commits into
haofeng0705 wants to merge 3 commits into
Conversation
typefield
requested changes
Oct 20, 2026
typefield
left a comment
Collaborator
There was a problem hiding this comment.
Review
结论:Request changes。CLM 的下载/写入前中止和 throw 保留调用方行为做得正确;PowerShell 5.1 使用的语法本身也没有明显兼容性问题。但 WDAC 审计模式的关键语义目前没有被可靠验证。
[高风险] GetTempPath() 不能可靠区分审计模式和真正受限模式
涉及 scripts/install.ps1:32-36 和 scripts/install-devapp.ps1:17-21。
这里用 [System.IO.Path]::GetTempPath() 的成功/失败来决定是否放行非 FullLanguage。但 PowerShell 的 WDAC audit-only 行为存在已知例外:会报告 ConstrainedLanguage,同时某些操作看起来像 FullLanguage,而 [pscustomobject] 仍可能失败(PowerShell/PowerShell#20768)。主安装脚本在 scripts/install.ps1:73 就会执行第一个 [pscustomobject]。
因此当前逻辑存在两种未覆盖结果:
- 审计模式允许
GetTempPath():预检放行,随后仍可能在[pscustomobject]处失败,达不到“下载/写入前中止”; - 审计模式也拒绝该方法调用:预检会把本应可继续的审计模式误判为强制 CLM。
新增测试只是在 pwsh 中手动设置 LanguageMode = ConstrainedLanguage,不能区分这两种真实 WDAC audit 行为。请在 Windows PowerShell 5.1 和实际 WDAC audit policy 上验证,并明确选择/实现预期行为;不要直接用 [pscustomobject] 作为探针,因为已知 CLM 失败可能污染进程级转换缓存。
其它方面:预检位置正确,throw 在 irm | iex 中不会关闭调用方,未捕获执行也返回非零,新增测试覆盖了这些路径。
Refs #650 Reject other reported modes before installer initialization, including WDAC audit reports. Update documentation and add simulated audit-report cases.
This branch has not been deployed
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.
Refs #650
Summary
install.ps1和install-devapp.ps1要求FullLanguage,在初始化、构造注册表、下载或修改安装内容之前检查报告的语言模式。其他模式通过throw给出明确诊断,保留已有的irm | iex调用方终端;未捕获异常时返回非零退出码。GetTempPath()方法探针。单次 .NET 方法调用成功不能证明后续[pscustomobject]等安装操作可用;预检也不使用可能污染转换缓存的[pscustomobject]探针。ConstrainedLanguage,同样提前停止。 这收紧了原方案的支持范围,不再承诺通过探针保留审计模式的安装行为,也不将审计策略误称为强制限制。原问题的安装脚本在下载阶段调用
System.IO.Path.GetTempPath()时失败;后续版本的脚本更早在[pscustomobject]注册表初始化阶段失败。预检必须放在文件顶部。本 PR 改善诊断与停止行为,不提供完整的 ConstrainedLanguage 安装支持,不改变 ExecutionPolicy 或应用控制策略。
Risk tier
部分 WDAC 审计环境原本可能继续安装,现在只要报告非
FullLanguage就会停止。脚本明确要求受支持的语言模式;受管设备使用 IT 批准的分发流程,npm/手动安装仍以组织策略允许为条件。仅涉及 7 个文件;不改变下载校验、技能事务、缓存 ACL、命令接口或工作流。
Verification
.changes/650-powershell-language-mode.md。CHANGELOG.md。旧提交
6bb71a54627f798db1c3ffb041003c366aedbfe2的 6 个预检场景及 10 项定向 PowerShell 回归曾在 macOS pwsh 7.6.7 上通过;这些历史结果不能作为本次修订通过的证据。新增用例在 FullLanguage 引擎里替换预检读取的模式值,先确认
GetTempPath()可成功,再检查安装器仍提前拒绝。它用于覆盖原探针会错误放行的分支,不代表真实 WDAC 策略验证。Notes
替代安装方式也可能被组织应用控制阻止。文档不建议关闭安全策略;若需要支持报告 ConstrainedLanguage 的审计环境,应另行取得原生 Windows 策略证据并设计可靠方案。
相关上游问题:PowerShell #20768、PowerShell #28128。