Skip to content

Commit d7ec017

Browse files
author
SqlRush
committed
Guard PowerShell Get-ChildItem expressions
1 parent 6fcbfcc commit d7ec017

4 files changed

Lines changed: 8 additions & 0 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ M5 补充:PowerShell read-only classifier 收紧 `Test-Path`,继续允许安
245245

246246
M5 补充:PowerShell read-only classifier 收紧 `Get-Acl`,继续允许安全相对路径和普通 literal filter/include/exclude 参数,但拒绝动态表达式参数和越界路径。
247247

248+
M5 补充:PowerShell read-only classifier 收紧 `Get-ChildItem`,继续允许安全相对路径、literal wildcard filter/include/exclude 和常见 attributes/depth 参数,但拒绝动态表达式参数和越界路径。
249+
248250
M5 补充:Bash 前台输出和 `BashOutput` 现在都走统一 tool-result budget 截断/落盘路径;`BashOutput` 增加 100k 最大结果限制,大后台输出会保存完整内容并返回 `full_output_path` 元数据。
249251

250252
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
@@ -233,6 +233,7 @@ test/parity/ # golden tests against TS/official behavior
233233
- 本轮补充:PowerShell read-only classifier 收紧 `Format-Hex`,继续允许安全相对路径和普通 literal `-InputObject`,但拒绝动态表达式输入对象和越界路径。
234234
- 本轮补充:PowerShell read-only classifier 收紧 `Test-Path`,继续允许安全相对路径和普通 literal 过滤/类型参数,但拒绝动态表达式、hashtable 参数和越界路径。
235235
- 本轮补充:PowerShell read-only classifier 收紧 `Get-Acl`,继续允许安全相对路径和普通 literal filter/include/exclude 参数,但拒绝动态表达式参数和越界路径。
236+
- 本轮补充:PowerShell read-only classifier 收紧 `Get-ChildItem`,继续允许安全相对路径、literal wildcard filter/include/exclude 和常见 attributes/depth 参数,但拒绝动态表达式参数和越界路径。
236237
- 本轮补充:`BashOutput` 现在设置 100k 最大结果大小,和前台 `Bash` 一起覆盖大输出 tool-result preview 截断、完整输出落盘及 `full_output_path` 元数据。
237238
- 本轮补充:Bash/PowerShell 后台命令现在会通过 tool progress 通道发 started/finished 事件,记录后台 ID、shell/status、exit/timed_out/cancelled、duration、时间戳和 stdout/stderr byte count,且 completed、timed_out、cancelled 终态测试确保 progress 不携带 command 文本。
238239
- 本轮补充: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
@@ -1223,6 +1223,7 @@ var powerShellReadOnlyCmdlets = map[string]powerShellReadOnlyConfig{
12231223
pathFlags: stringSet("path", "literalpath"),
12241224
valueFlags: stringSet("filter", "include", "exclude", "depth", "attributes"),
12251225
validatePositionalsAsPaths: true,
1226+
rejectExpressionValues: true,
12261227
},
12271228
"get-content": {
12281229
allowedFlags: stringSet("path", "literalpath", "totalcount", "head", "first", "tail", "raw", "encoding", "delimiter", "readcount"),

internal/tools/powershell/tools_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ func TestPowerShellCommandClassification(t *testing.T) {
104104
"Get-ChildItem -Force",
105105
"Get-ChildItem -Filter '*.go' ./internal",
106106
"Get-ChildItem -Depth 2 ./internal",
107+
"Get-ChildItem -Include '*.go' ./internal",
108+
"Get-ChildItem -Attributes Directory ./internal",
107109
"Get-ChildItem ./internal",
108110
"Get-Content README.md",
109111
"Get-Content -Raw README.md",
@@ -299,6 +301,8 @@ func TestPowerShellCommandClassification(t *testing.T) {
299301
`Get-Content \\server\share\secret.txt`,
300302
"Get-ChildItem ~",
301303
`Get-Item HKLM:\Software`,
304+
"Get-ChildItem -Filter $env:SECRET ./internal",
305+
"Get-ChildItem -Attributes @{Name='Directory'} ./internal",
302306
"Get-Content '$HOME/file'",
303307
"Select-String TODO /etc/passwd",
304308
"sls TODO /etc/passwd",

0 commit comments

Comments
 (0)