larry-zy commented on code in PR #1594: URL: https://github.com/apache/dubbo-admin/pull/1594#discussion_r4465152926
########## 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] Redact the complete Cookie header value in text inputs The unquoted-value branch stops at a semicolon, so `Cookie: theme=dark; JSESSIONID=review-session-cookie-fixture` becomes `Cookie: [REDACTED]; JSESSIONID=review-session-cookie-fixture`. The session credential remains visible because `JSESSIONID` is not independently recognized as a sensitive assignment. I reproduced this at the reviewed head through `SanitizeText`, the actual `modelInputView` boundary, and a string attribute logged through `NewRedactingHandler`; canonical message text remains unchanged. Consequently, pasting an ordinary multi-cookie HTTP header into a conversation or including it in an upstream error still exposes the authentication cookie to the model and operational logs. Please handle Cookie headers separately so the full header value is redacted, and add multi-cookie regressions at the text, model-input, and logging boundaries. ########## 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] Recognize single-quoted YAML credential keys The separator allows an optional double quote after the sensitive key but no single quote. As a result, valid YAML such as `'password': 'review-yaml-password-fixture'` is returned unchanged by `SanitizeText` with no findings. I validated the fixture with the YAML parser and reproduced the leak through `modelInputView`. The same document also passes `NewKnowledgeIndexPolicy().Prepare` and the public `RAG.Index` entry point, which invokes the index backend with the plaintext credential. A user pasting or indexing a configuration file can therefore bypass the new sensitive-data boundary merely by using a standard YAML quoting form. Please support single-quoted sensitive keys at the text boundary, or inspect a safely parsed temporary YAML view, and add regressions for model input and index rejection while preserving canonical messages. -- 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]
