Qiao-yq commented on code in PR #1594:
URL: https://github.com/apache/dubbo-admin/pull/1594#discussion_r4491415957


##########
ai/security/sanitizer.go:
##########
@@ -0,0 +1,365 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package security
+
+import (
+       "encoding/base64"
+       "encoding/json"
+       "fmt"
+       "net/http"
+       "net/url"
+       "regexp"
+       "sort"
+       "strings"
+)
+
+const (
+       SanitizerRuleVersion = "2026-10-10.v1"
+       redactedValue        = "[REDACTED]"
+       maxStructuredBytes   = 1 << 20
+       maxStructuredDepth   = 32
+)
+
+const (
+       RuleSensitiveField       = "secret.sensitive-field"
+       RuleAuthorization        = "secret.authorization"
+       RuleCredentialAssignment = "secret.credential-assignment"
+       RulePrivateKey           = "secret.private-key"
+       RuleJWT                  = "secret.jwt"
+       RuleAPIKey               = "secret.api-key"
+       RuleEncodedSecret        = "secret.encoded"
+)
+
+var (
+       privateKeyPattern           = regexp.MustCompile(`(?is)-----BEGIN 
[A-Z0-9 ]*PRIVATE KEY-----.*?-----END [A-Z0-9 ]*PRIVATE KEY-----`)
+       authorizationPattern        = 
regexp.MustCompile(`(?i)\b(?:bearer|basic)\s+[A-Za-z0-9._~+/=-]+`)
+       jwtPattern                  = 
regexp.MustCompile(`\beyJ[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{4,}\b`)
+       apiKeyPattern               = 
regexp.MustCompile(`\b(?:sk-[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9]{16,}|AIza[A-Za-z0-9_-]{20,}|xox[baprs]-[A-Za-z0-9-]{16,})\b`)
+       credentialAssignmentPattern = 
regexp.MustCompile(`(?i)\b(authorization|proxy[-_]?authorization|cookie|set[-_]?cookie|token|access[-_]?token|refresh[-_]?token|api[-_]?key|apikey|password|passwd|secret|client[-_]?secret|client[-_]?key[-_]?data|client[-_]?certificate[-_]?data)\b(\s*"?\s*(?::|=|%3[dD])\s*)(?:"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'|[^\s,;&\r\n]+)`)

Review Comment:
   @larry-zy Fixed in 5744bbe.
   
   `cookie`/`set-cookie` no longer share the generic assignment rule. A 
dedicated header rule redacts `Cookie:`/`Set-Cookie:` through end of line, so 
`Cookie: theme=dark; JSESSIONID=...` becomes `Cookie: [REDACTED]`; 
`cookie=`/`cookie%3D` forms consume the whole semicolon list and stop at `&` to 
preserve unrelated query parameters.
   
   Regressions cover `SanitizeText`, `modelInputView` (canonical unchanged), 
`NewRedactingHandler`, `NewKnowledgeIndexPolicy().Prepare`, the concrete 
indexer, and public `RAG.Index` (backend not reached). `go test -count=1` and 
`go vet` pass.



##########
ai/security/sanitizer.go:
##########
@@ -0,0 +1,365 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package security
+
+import (
+       "encoding/base64"
+       "encoding/json"
+       "fmt"
+       "net/http"
+       "net/url"
+       "regexp"
+       "sort"
+       "strings"
+)
+
+const (
+       SanitizerRuleVersion = "2026-10-10.v1"
+       redactedValue        = "[REDACTED]"
+       maxStructuredBytes   = 1 << 20
+       maxStructuredDepth   = 32
+)
+
+const (
+       RuleSensitiveField       = "secret.sensitive-field"
+       RuleAuthorization        = "secret.authorization"
+       RuleCredentialAssignment = "secret.credential-assignment"
+       RulePrivateKey           = "secret.private-key"
+       RuleJWT                  = "secret.jwt"
+       RuleAPIKey               = "secret.api-key"
+       RuleEncodedSecret        = "secret.encoded"
+)
+
+var (
+       privateKeyPattern           = regexp.MustCompile(`(?is)-----BEGIN 
[A-Z0-9 ]*PRIVATE KEY-----.*?-----END [A-Z0-9 ]*PRIVATE KEY-----`)
+       authorizationPattern        = 
regexp.MustCompile(`(?i)\b(?:bearer|basic)\s+[A-Za-z0-9._~+/=-]+`)
+       jwtPattern                  = 
regexp.MustCompile(`\beyJ[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{4,}\b`)
+       apiKeyPattern               = 
regexp.MustCompile(`\b(?:sk-[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9]{16,}|AIza[A-Za-z0-9_-]{20,}|xox[baprs]-[A-Za-z0-9-]{16,})\b`)
+       credentialAssignmentPattern = 
regexp.MustCompile(`(?i)\b(authorization|proxy[-_]?authorization|cookie|set[-_]?cookie|token|access[-_]?token|refresh[-_]?token|api[-_]?key|apikey|password|passwd|secret|client[-_]?secret|client[-_]?key[-_]?data|client[-_]?certificate[-_]?data)\b(\s*"?\s*(?::|=|%3[dD])\s*)(?:"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'|[^\s,;&\r\n]+)`)

Review Comment:
   @larry-zy Fixed in 5744bbe.
   
   The assignment separator now accepts either quote (`\s*["']?\s*`), so 
`'password': '...'` matches. Replacement quote style follows the value itself 
rather than the key, so the sanitized output keeps the value's scalar style. 
`SanitizerRuleVersion` is bumped to `2026-11-04.v1` because rule semantics 
changed.
   
   Regressions cover `SanitizeText`, `modelInputView`, 
`NewKnowledgeIndexPolicy().Prepare`, the concrete indexer, and public 
`RAG.Index` (backend not reached). `go test -count=1` and `go vet` pass.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to