Skip to content

Commit 022b591

Browse files
author
SqlRush
committed
Tighten PowerShell system info queries
1 parent 1fb1766 commit 022b591

4 files changed

Lines changed: 29 additions & 5 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ M5 补充:PowerShell read-only classifier 收紧网络/DNS 查询类 cmdlet,
261261

262262
M5 补充:PowerShell read-only classifier 收紧事件日志/CIM 查询类 cmdlet,`Get-EventLog``Get-CimClass` 继续允许普通 literal 查询参数,但拒绝 `$env:`、hashtable 等动态表达式参数。
263263

264+
M5 补充:PowerShell read-only classifier 收紧系统信息类 cmdlet,`Get-ComputerInfo` 从 allow-all 改为 literal `-Property` 白名单,`Get-Host`/`Get-Culture`/`Get-UICulture`/`Get-Uptime` 不再接受未知 flag 或位置参数。
265+
264266
M5 补充:Bash 前台输出和 `BashOutput` 现在都走统一 tool-result budget 截断/落盘路径;`BashOutput` 增加 100k 最大结果限制,大后台输出会保存完整内容并返回 `full_output_path` 元数据。
265267

266268
M5 补充:Bash/PowerShell 后台任务现在会发 `*_background_started``*_background_finished` tool progress 事件,包含后台 ID、shell/status、exit/timed_out/cancelled、duration、时间戳和输出字节数,不携带 command 文本;completed、timed_out、cancelled 终态均已覆盖测试。

docs/claude-code-go-rewrite-plan.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ test/parity/ # golden tests against TS/official behavior
241241
- 本轮补充:PowerShell read-only classifier 收紧 metadata 查询类 cmdlet,`Get-Location`/`Get-Date`/`Get-PSDrive`/`Get-Module`/`Get-Alias`/`Get-History`/`Get-TimeZone` 继续允许普通 literal 参数,但拒绝动态表达式参数。
242242
- 本轮补充:PowerShell read-only classifier 收紧网络/DNS 查询类 cmdlet,`Get-NetAdapter`/`Get-NetIPAddress`/`Get-NetIPConfiguration`/`Get-NetRoute`/`Get-DnsClientCache`/`Get-DnsClient` 继续允许普通 literal 查询参数,但拒绝 `$env:`、hashtable 等动态表达式参数。
243243
- 本轮补充:PowerShell read-only classifier 收紧事件日志/CIM 查询类 cmdlet,`Get-EventLog``Get-CimClass` 继续允许普通 literal 查询参数,但拒绝 `$env:`、hashtable 等动态表达式参数。
244+
- 本轮补充:PowerShell read-only classifier 收紧系统信息类 cmdlet,`Get-ComputerInfo` 从 allow-all 改为 literal `-Property` 白名单,`Get-Host`/`Get-Culture`/`Get-UICulture`/`Get-Uptime` 不再接受未知 flag 或位置参数。
244245
- 本轮补充:`BashOutput` 现在设置 100k 最大结果大小,和前台 `Bash` 一起覆盖大输出 tool-result preview 截断、完整输出落盘及 `full_output_path` 元数据。
245246
- 本轮补充:Bash/PowerShell 后台命令现在会通过 tool progress 通道发 started/finished 事件,记录后台 ID、shell/status、exit/timed_out/cancelled、duration、时间戳和 stdout/stderr byte count,且 completed、timed_out、cancelled 终态测试确保 progress 不携带 command 文本。
246247
- 本轮补充:WebSearch domain filters 现在在 schema 层声明 array `items:string`,通用 tool schema validator 同步支持 `items` 校验;`allowed_domains`/`blocked_domains` 会拒绝空字符串、URL/port、非法 wildcard 和非域名 label。

internal/tools/powershell/tools.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ type powerShellReadOnlyConfig struct {
11791179
valueFlags map[string]bool
11801180
allowAllFlags bool
11811181
rejectExpressionValues bool
1182+
rejectPositionals bool
11821183
validatePositionalsAsPaths bool
11831184
pathPositionalsAfterLiterals int
11841185
}
@@ -1409,19 +1410,27 @@ var powerShellReadOnlyCmdlets = map[string]powerShellReadOnlyConfig{
14091410
rejectExpressionValues: true,
14101411
},
14111412
"get-computerinfo": {
1412-
allowAllFlags: true,
1413+
allowedFlags: stringSet("property"),
1414+
valueFlags: stringSet("property"),
1415+
rejectExpressionValues: true,
14131416
},
14141417
"get-host": {
1415-
allowAllFlags: true,
1418+
rejectExpressionValues: true,
1419+
rejectPositionals: true,
14161420
},
14171421
"get-culture": {
1418-
allowAllFlags: true,
1422+
allowedFlags: stringSet("nouseroverrides"),
1423+
rejectExpressionValues: true,
1424+
rejectPositionals: true,
14191425
},
14201426
"get-uiculture": {
1421-
allowAllFlags: true,
1427+
rejectExpressionValues: true,
1428+
rejectPositionals: true,
14221429
},
14231430
"get-uptime": {
1424-
allowAllFlags: true,
1431+
allowedFlags: stringSet("since"),
1432+
rejectExpressionValues: true,
1433+
rejectPositionals: true,
14251434
},
14261435
"get-netadapter": {
14271436
allowedFlags: stringSet("name", "interfacedescription", "interfaceindex", "physical"),
@@ -1736,6 +1745,8 @@ func readOnlyPowerShellArgs(words []string, config powerShellReadOnlyConfig) boo
17361745
if !safeRelativePowerShellPath(word) {
17371746
return false
17381747
}
1748+
} else if config.rejectPositionals {
1749+
return false
17391750
} else if !safePowerShellParameterValue(word, config.rejectExpressionValues) {
17401751
return false
17411752
}

internal/tools/powershell/tools_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,13 @@ func TestPowerShellCommandClassification(t *testing.T) {
210210
"gu -AsString value",
211211
"Get-TimeZone -ListAvailable",
212212
"Get-ComputerInfo",
213+
"Get-ComputerInfo -Property CsName",
213214
"Get-Host",
214215
"Get-Culture",
216+
"Get-Culture -NoUserOverrides",
215217
"Get-UICulture",
216218
"Get-Uptime",
219+
"Get-Uptime -Since",
217220
"Get-NetAdapter -Physical",
218221
"Get-NetAdapter -Name Ethernet",
219222
"Get-NetIPAddress -AddressFamily IPv4",
@@ -348,8 +351,15 @@ func TestPowerShellCommandClassification(t *testing.T) {
348351
"Get-Module -CimSession server",
349352
"Get-Date -ComputerName server",
350353
"Get-ComputerInfo -CimSession server",
354+
"Get-ComputerInfo -Property $env:PROP",
355+
"Get-ComputerInfo -Unknown CsName",
351356
"Get-Host -AsJob",
357+
"Get-Host name",
358+
"Get-Host -Unknown value",
352359
"Get-Culture -Credential admin",
360+
"Get-Culture en-US",
361+
"Get-UICulture en-US",
362+
"Get-Uptime -Since:$env:SINCE",
353363
"Start-Sleep -Seconds $env:SECRET",
354364
`Get-ItemProperty HKLM:\Software -Name Path`,
355365
`gip HKLM:\Software -Name Path`,

0 commit comments

Comments
 (0)