内置的 HTTP 破坏性规则只认 DELETE 方法(curl -X DELETE、requests.delete(、 method:'DELETE'),路径类规则的词表又只有 /clear /wipe /flush /purge /truncate /drop /destroy /factory-reset /reset-all。而多数应用的删除接口用 GET/POST 就能 触发,于是 `curl 'http://t/api/user/delete?id=1'` 不命中任何内置规则,会真实删掉 目标数据。 补一条 deny 规则覆盖 /delete /del /remove /unlink /erase /destroy,允许 /deleteAll、/delete_user、/delete-user 这类后缀形式(destroy 是重复覆盖:v1 那条 不允许后缀,/destroyAll 是漏的)。动词后强制跟分隔符,/delivery、/details、 /delta、/delegate 不会被误拦。 种子走独立标记位 intercept_default_rules_v3,已有实例升级后也会拿到——改 v1 的 字面量对老库无效(标记位已是 done)。插入带 WHERE NOT EXISTS 兜底,标记位丢失也 不会插重复。正则提为包级常量,配纯正则单测(不依赖 DB)覆盖命中与误伤两侧。
47 lines
1.7 KiB
Go
47 lines
1.7 KiB
Go
package db
|
|
|
|
import (
|
|
"regexp"
|
|
"testing"
|
|
)
|
|
|
|
// 内置「删除类接口路径」规则匹配的是整个 tool_input JSON 串,因此用例直接以
|
|
// JSON 形态给出,与 Interceptor 实际拿到的 subject 一致。
|
|
func TestDeleteEndpointPathPattern(t *testing.T) {
|
|
re := regexp.MustCompile(deleteEndpointPathPattern)
|
|
|
|
hit := []string{
|
|
`{"command":"curl -s 'http://t.com/api/user/delete?id=1'"}`, // GET 打删除接口
|
|
`{"command":"curl -X POST http://t.com/admin/delete -d id=1"}`, // POST 打删除接口
|
|
`{"command":"curl 'http://t.com/api/deleteAll'"}`,
|
|
`{"command":"curl 'http://t.com/api/delete_user?id=1'"}`,
|
|
`{"command":"curl 'http://t.com/api/delete-user?id=1'"}`,
|
|
`{"url":"http://t.com/api/remove?id=1"}`,
|
|
`{"command":"curl http://t.com/files/unlink/3"}`,
|
|
`{"command":"curl http://t.com/api/del?id=2"}`,
|
|
`{"command":"curl -X POST http://t/v1/erase"}`,
|
|
`{"command":"curl http://t/admin/destroyAll"}`, // v1 的路径规则不允许后缀,这里补上
|
|
}
|
|
for _, s := range hit {
|
|
if !re.MatchString(s) {
|
|
t.Errorf("应命中却放行: %s", s)
|
|
}
|
|
}
|
|
|
|
// 动词后必须跟分隔符,避免 /delivery、/details 这类只读路径被误拦。
|
|
miss := []string{
|
|
`{"command":"curl 'http://t.com/api/delivery?id=1'"}`,
|
|
`{"command":"curl 'http://t.com/order/details'"}`,
|
|
`{"command":"curl 'http://t.com/api/delta/sync'"}`,
|
|
`{"command":"curl 'http://t.com/user/delegate'"}`,
|
|
`{"command":"curl 'http://delete.example.com/'"}`, // 删除动词出现在域名而非路径
|
|
`{"command":"curl 'http://t.com/remote/status'"}`,
|
|
`{"command":"nmap -p80 10.0.0.1"}`,
|
|
}
|
|
for _, s := range miss {
|
|
if re.MatchString(s) {
|
|
t.Errorf("误拦: %s", s)
|
|
}
|
|
}
|
|
}
|