Skip to content

Commit 9a57518

Browse files
author
SqlRush
committed
Guard PowerShell metadata query expressions
1 parent 9c3b846 commit 9a57518

4 files changed

Lines changed: 30 additions & 14 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ M5 补充:PowerShell read-only classifier 收紧 `Get-ItemProperty`/`Get-ItemP
255255

256256
M5 补充:PowerShell read-only classifier 收紧 `Get-Process`/`Get-Service`,继续允许普通 literal name/id/displayName/include/exclude 查询参数,但拒绝动态表达式参数。
257257

258+
M5 补充:PowerShell read-only classifier 收紧 metadata 查询类 cmdlet,`Get-Location`/`Get-Date`/`Get-PSDrive`/`Get-Module`/`Get-Alias`/`Get-History`/`Get-TimeZone` 继续允许普通 literal 参数,但拒绝动态表达式参数。
259+
258260
M5 补充:Bash 前台输出和 `BashOutput` 现在都走统一 tool-result budget 截断/落盘路径;`BashOutput` 增加 100k 最大结果限制,大后台输出会保存完整内容并返回 `full_output_path` 元数据。
259261

260262
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
@@ -238,6 +238,7 @@ test/parity/ # golden tests against TS/official behavior
238238
- 本轮补充:PowerShell read-only classifier 收紧 `Select-String`/`sls`,继续允许安全相对路径和普通 literal pattern/context/inputObject 参数,但拒绝动态表达式参数和越界路径。
239239
- 本轮补充:PowerShell read-only classifier 收紧 `Get-ItemProperty`/`Get-ItemPropertyValue``Get-FileHash`,继续允许普通 literal name/algorithm 参数,但拒绝动态表达式参数和越界路径。
240240
- 本轮补充:PowerShell read-only classifier 收紧 `Get-Process`/`Get-Service`,继续允许普通 literal name/id/displayName/include/exclude 查询参数,但拒绝动态表达式参数。
241+
- 本轮补充:PowerShell read-only classifier 收紧 metadata 查询类 cmdlet,`Get-Location`/`Get-Date`/`Get-PSDrive`/`Get-Module`/`Get-Alias`/`Get-History`/`Get-TimeZone` 继续允许普通 literal 参数,但拒绝动态表达式参数。
241242
- 本轮补充:`BashOutput` 现在设置 100k 最大结果大小,和前台 `Bash` 一起覆盖大输出 tool-result preview 截断、完整输出落盘及 `full_output_path` 元数据。
242243
- 本轮补充:Bash/PowerShell 后台命令现在会通过 tool progress 通道发 started/finished 事件,记录后台 ID、shell/status、exit/timed_out/cancelled、duration、时间戳和 stdout/stderr byte count,且 completed、timed_out、cancelled 终态测试确保 progress 不携带 command 文本。
243244
- 本轮补充: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: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,32 +1374,39 @@ var powerShellReadOnlyCmdlets = map[string]powerShellReadOnlyConfig{
13741374
rejectExpressionValues: true,
13751375
},
13761376
"get-location": {
1377-
allowedFlags: stringSet("psprovider", "psdrive", "stack", "stackname"),
1378-
valueFlags: stringSet("psprovider", "psdrive", "stackname"),
1377+
allowedFlags: stringSet("psprovider", "psdrive", "stack", "stackname"),
1378+
valueFlags: stringSet("psprovider", "psdrive", "stackname"),
1379+
rejectExpressionValues: true,
13791380
},
13801381
"get-date": {
1381-
allowedFlags: stringSet("date", "format", "uformat", "displayhint", "asutc"),
1382-
valueFlags: stringSet("date", "format", "uformat", "displayhint"),
1382+
allowedFlags: stringSet("date", "format", "uformat", "displayhint", "asutc"),
1383+
valueFlags: stringSet("date", "format", "uformat", "displayhint"),
1384+
rejectExpressionValues: true,
13831385
},
13841386
"get-psdrive": {
1385-
allowedFlags: stringSet("name", "psprovider", "scope"),
1386-
valueFlags: stringSet("name", "psprovider", "scope"),
1387+
allowedFlags: stringSet("name", "psprovider", "scope"),
1388+
valueFlags: stringSet("name", "psprovider", "scope"),
1389+
rejectExpressionValues: true,
13871390
},
13881391
"get-module": {
1389-
allowedFlags: stringSet("name", "listavailable", "all", "fullyqualifiedname", "psedition"),
1390-
valueFlags: stringSet("name", "fullyqualifiedname", "psedition"),
1392+
allowedFlags: stringSet("name", "listavailable", "all", "fullyqualifiedname", "psedition"),
1393+
valueFlags: stringSet("name", "fullyqualifiedname", "psedition"),
1394+
rejectExpressionValues: true,
13911395
},
13921396
"get-alias": {
1393-
allowedFlags: stringSet("name", "definition", "scope", "exclude"),
1394-
valueFlags: stringSet("name", "definition", "scope", "exclude"),
1397+
allowedFlags: stringSet("name", "definition", "scope", "exclude"),
1398+
valueFlags: stringSet("name", "definition", "scope", "exclude"),
1399+
rejectExpressionValues: true,
13951400
},
13961401
"get-history": {
1397-
allowedFlags: stringSet("id", "count"),
1398-
valueFlags: stringSet("id", "count"),
1402+
allowedFlags: stringSet("id", "count"),
1403+
valueFlags: stringSet("id", "count"),
1404+
rejectExpressionValues: true,
13991405
},
14001406
"get-timezone": {
1401-
allowedFlags: stringSet("name", "id", "listavailable"),
1402-
valueFlags: stringSet("name", "id"),
1407+
allowedFlags: stringSet("name", "id", "listavailable"),
1408+
valueFlags: stringSet("name", "id"),
1409+
rejectExpressionValues: true,
14031410
},
14041411
"get-computerinfo": {
14051412
allowAllFlags: true,

internal/tools/powershell/tools_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ func TestPowerShellCommandClassification(t *testing.T) {
392392
"Get-Process -Id @{N=1}",
393393
"Get-Service -Name $env:SECRET",
394394
"Get-Service -DisplayName @{N='ssh-agent'}",
395+
"Get-Date -Format $env:FORMAT",
396+
"Get-PSDrive -Name $env:DRIVE",
397+
"Get-Module -Name @{N='module'}",
398+
"Get-Alias -Name $env:ALIAS",
399+
"Get-History -Count @{N=5}",
400+
"Get-TimeZone -Id $env:TZ",
395401
"Write-Output `$env:SECRET",
396402
"Get-NetAdapter -CimSession server",
397403
"Get-DnsClientCache -CimSession server",

0 commit comments

Comments
 (0)