larry-zy commented on code in PR #1594:
URL: https://github.com/apache/dubbo-admin/pull/1594#discussion_r4376649960


##########
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:
   [P1] Consume escaped quotes as part of the credential value
   
   The quoted-value alternative stops at an escaped quote inside a valid JSON 
string. For example, 
`{"password":"prefix\"review-suffix-secret","enabled":true}` is transformed 
into `{"password":"[REDACTED]"review-suffix-secret","enabled":true}`: the 
credential suffix is still visible. I reproduced this at this head through both 
`SanitizeText` and `modelInputView`, which forwards the surviving suffix to the 
model while leaving canonical history unchanged. Please make quoted-value 
consumption escape-aware, or parse valid JSON into a temporary structured view 
before redaction, and add escaped-quote/backslash cases to the model-boundary 
regression tests.



-- 
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