feat: 加固 Agent CLI 执行边界并更新模型目录
收紧 SSH 命令护栏、权限校验与远程执行会话,并同步主流大模型供应商列表。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
67660ae1d6
commit
2fd1624bec
18 files changed
+480
-49
No files matched your search
@@ -15,7 +15,7 @@ var sensitivePatterns = []*regexp.Regexp{
|
||||
regexp.MustCompile(`(?i)((?:mysql|postgres|postgresql|redis|mongodb)://[^:\s/@]+:)[^@\s]+(@)`),
|
||||
regexp.MustCompile(`(?is)-----BEGIN [A-Z ]*PRIVATE KEY-----.*?-----END [A-Z ]*PRIVATE KEY-----`),
|
||||
regexp.MustCompile(`(?i)((?:Cookie|Set-Cookie):\s*)[^\r\n]+`),
|
||||
regexp.MustCompile(`(?i)(AKIA[0-9A-Z]{16})`),
|
||||
regexp.MustCompile(`(?i)AKIA[0-9A-Z]{16}`),
|
||||
}
|
||||
|
||||
var sensitiveKeys = map[string]bool{
|
||||
@@ -65,6 +65,18 @@ func SanitizeJSON(raw string) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// SanitizeMap 返回脱敏后的参数副本,避免事件、审计和记忆泄露工具参数中的凭证。 // Logan.Li
|
||||
func SanitizeMap(input map[string]interface{}) map[string]interface{} {
|
||||
if input == nil {
|
||||
return nil
|
||||
}
|
||||
sanitized, ok := sanitizeValue(input).(map[string]interface{})
|
||||
if !ok {
|
||||
return map[string]interface{}{}
|
||||
}
|
||||
return sanitized
|
||||
}
|
||||
|
||||
func sanitizeValue(v interface{}) interface{} {
|
||||
switch val := v.(type) {
|
||||
case map[string]interface{}:
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
)
|
||||
|
||||
func TestSanitizeTextMasksCommonSecrets(t *testing.T) {
|
||||
input := "Authorization: Bearer abcdefghijklmnopqrstuvwxyz password=secret123 mysql://root:pass@db/prod"
|
||||
input := "Authorization: Bearer abcdefghijklmnopqrstuvwxyz password=secret123 mysql://root:pass@db/prod AKIA1234567890ABCDEF"
|
||||
got := SanitizeText(input)
|
||||
for _, leak := range []string{"abcdefghijklmnopqrstuvwxyz", "secret123", "root:pass@db"} {
|
||||
for _, leak := range []string{"abcdefghijklmnopqrstuvwxyz", "secret123", "root:pass@db", "AKIA1234567890ABCDEF"} {
|
||||
if strings.Contains(got, leak) {
|
||||
t.Fatalf("敏感信息未脱敏: %s in %s", leak, got)
|
||||
}
|
||||
@@ -29,3 +29,22 @@ func TestSanitizeJSONMasksSensitiveKeys(t *testing.T) {
|
||||
t.Fatalf("非敏感字段不应被改写: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeMapReturnsMaskedCopy(t *testing.T) {
|
||||
input := map[string]interface{}{
|
||||
"command": "curl -H 'Authorization: Bearer abcdefghijklmnop' https://example.test",
|
||||
"nested": map[string]interface{}{"password": "plain-secret"},
|
||||
}
|
||||
|
||||
got := SanitizeMap(input)
|
||||
if got["command"] == input["command"] {
|
||||
t.Fatal("命令中的令牌未脱敏")
|
||||
}
|
||||
nested := got["nested"].(map[string]interface{})
|
||||
if nested["password"] != "[REDACTED]" {
|
||||
t.Fatalf("密码字段未脱敏: %#v", nested["password"])
|
||||
}
|
||||
if input["nested"].(map[string]interface{})["password"] != "plain-secret" {
|
||||
t.Fatal("脱敏不得修改原始参数")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user