Skip to content

Commit 3dc6c41

Browse files
author
SqlRush
committed
Guard PowerShell Test-Path expressions
1 parent 874eb61 commit 3dc6c41

4 files changed

Lines changed: 11 additions & 0 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ M5 补充:PowerShell read-only classifier 新增 `Join-Path` 安全路径字
241241

242242
M5 补充:PowerShell read-only classifier 收紧 `Format-Hex`,继续允许安全相对路径和普通 literal `-InputObject`,但拒绝动态表达式输入对象和越界路径。
243243

244+
M5 补充:PowerShell read-only classifier 收紧 `Test-Path`,继续允许安全相对路径和普通 literal 过滤/类型参数,但拒绝动态表达式、hashtable 参数和越界路径。
245+
244246
M5 补充:Bash 前台输出和 `BashOutput` 现在都走统一 tool-result budget 截断/落盘路径;`BashOutput` 增加 100k 最大结果限制,大后台输出会保存完整内容并返回 `full_output_path` 元数据。
245247

246248
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
@@ -231,6 +231,7 @@ test/parity/ # golden tests against TS/official behavior
231231
- 本轮补充:PowerShell read-only classifier 新增 `Split-Path` 安全路径字符串子集,允许安全相对 `Path`/`LiteralPath` 和 leaf/parent/qualifier/isAbsolute 输出形态,同时拒绝 `-Resolve`、绝对路径、父目录和变量路径。
232232
- 本轮补充:PowerShell read-only classifier 新增 `Join-Path` 安全路径字符串子集,允许安全相对 `Path`/`LiteralPath`/`ChildPath`/`AdditionalChildPath` 和 positional 形态,同时拒绝 `-Resolve`、绝对路径和变量路径。
233233
- 本轮补充:PowerShell read-only classifier 收紧 `Format-Hex`,继续允许安全相对路径和普通 literal `-InputObject`,但拒绝动态表达式输入对象和越界路径。
234+
- 本轮补充:PowerShell read-only classifier 收紧 `Test-Path`,继续允许安全相对路径和普通 literal 过滤/类型参数,但拒绝动态表达式、hashtable 参数和越界路径。
234235
- 本轮补充:`BashOutput` 现在设置 100k 最大结果大小,和前台 `Bash` 一起覆盖大输出 tool-result preview 截断、完整输出落盘及 `full_output_path` 元数据。
235236
- 本轮补充:Bash/PowerShell 后台命令现在会通过 tool progress 通道发 started/finished 事件,记录后台 ID、shell/status、exit/timed_out/cancelled、duration、时间戳和 stdout/stderr byte count,且 completed、timed_out、cancelled 终态测试确保 progress 不携带 command 文本。
236237
- 本轮补充: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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,7 @@ var powerShellReadOnlyCmdlets = map[string]powerShellReadOnlyConfig{
12421242
pathFlags: stringSet("path", "literalpath"),
12431243
valueFlags: stringSet("pathtype", "filter", "include", "exclude", "newerthan", "olderthan"),
12441244
validatePositionalsAsPaths: true,
1245+
rejectExpressionValues: true,
12451246
},
12461247
"resolve-path": {
12471248
allowedFlags: stringSet("path", "literalpath", "relative"),

internal/tools/powershell/tools_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ func TestPowerShellCommandClassification(t *testing.T) {
137137
"Resolve-Path README.md",
138138
"rvpa README.md",
139139
"rvpa -Relative ./internal",
140+
"Test-Path README.md",
141+
"Test-Path -Path README.md -PathType Leaf",
142+
"Test-Path -Path ./internal -Filter '*.go'",
140143
"Split-Path README.md -Leaf",
141144
"Split-Path -Path internal/tools/powershell/tools.go -Parent",
142145
"Split-Path -LiteralPath README.md -IsAbsolute",
@@ -337,6 +340,10 @@ func TestPowerShellCommandClassification(t *testing.T) {
337340
`gpv C:\Users\secret.txt -Name Mode`,
338341
`rvpa C:\Users\secret.txt`,
339342
"rvpa ../secret.txt",
343+
"Test-Path /etc/passwd",
344+
"Test-Path -Path $env:SECRET",
345+
"Test-Path -Path README.md -Filter $env:SECRET",
346+
"Test-Path -Path README.md -PathType @{Name='Leaf'}",
340347
"Split-Path /etc/passwd -Leaf",
341348
`Split-Path C:\Users\secret.txt -Leaf`,
342349
"Split-Path -Path $env:SECRET -Leaf",

0 commit comments

Comments
 (0)