This is an automated email from the ASF dual-hosted git repository.

Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new b696f3dda4 fix(logging): escape desensitize keywords (#7130)
b696f3dda4 is described below

commit b696f3dda423a7053bf16b79fdb4f76315e76103
Author: Liming Deng <[email protected]>
AuthorDate: Sat Sep 19 22:53:43 2026 +0800

    fix(logging): escape desensitize keywords (#7130)
---
 .../logging/desensitize/api/matcher/KeyWordMatch.java       |  5 +++--
 .../logging/desensitize/api/matcher/KeyWordMatchTest.java   | 13 +++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-desensitize-api/src/main/java/org/apache/shenyu/plugin/logging/desensitize/api/matcher/KeyWordMatch.java
 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-desensitize-api/src/main/java/org/apache/shenyu/plugin/logging/desensitize/api/matcher/KeyWordMatch.java
index 3961133729..6e429f4b8f 100644
--- 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-desensitize-api/src/main/java/org/apache/shenyu/plugin/logging/desensitize/api/matcher/KeyWordMatch.java
+++ 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-desensitize-api/src/main/java/org/apache/shenyu/plugin/logging/desensitize/api/matcher/KeyWordMatch.java
@@ -37,9 +37,10 @@ public class KeyWordMatch {
         keyWordSet.forEach(tempKeyWord -> {
             sb.append("(?i)");
             if (tempKeyWord.length() <= 6) {
-                sb.append(tempKeyWord);
+                sb.append(Pattern.quote(tempKeyWord));
             } else {
-                sb.append("^").append(tempKeyWord.substring(0, 
3)).append("(.*?)").append(tempKeyWord.substring(tempKeyWord.length() - 
3)).append("$");
+                sb.append("^").append(Pattern.quote(tempKeyWord.substring(0, 
3))).append("(.*?)")
+                        
.append(Pattern.quote(tempKeyWord.substring(tempKeyWord.length() - 
3))).append("$");
             }
             sb.append("||");
         });
diff --git 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-desensitize-api/src/test/java/org/apache/shenyu/plugin/logging/desensitize/api/matcher/KeyWordMatchTest.java
 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-desensitize-api/src/test/java/org/apache/shenyu/plugin/logging/desensitize/api/matcher/KeyWordMatchTest.java
index 37a4fdad19..881a1bcba3 100644
--- 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-desensitize-api/src/test/java/org/apache/shenyu/plugin/logging/desensitize/api/matcher/KeyWordMatchTest.java
+++ 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-desensitize-api/src/test/java/org/apache/shenyu/plugin/logging/desensitize/api/matcher/KeyWordMatchTest.java
@@ -46,4 +46,17 @@ class KeyWordMatchTest {
         Assertions.assertTrue(keyWordMatch.matches("test"));
         Assertions.assertFalse(keyWordMatch.matches("dsaer"));
     }
+
+    @Test
+    public void matchesKeywordsContainingRegexMetacharacters() {
+        Set<String> set = new HashSet<>();
+        set.add("a.b");
+        set.add("ab[secret]yz");
+        KeyWordMatch match = new KeyWordMatch(set);
+
+        Assertions.assertTrue(match.matches("a.b"));
+        Assertions.assertFalse(match.matches("axb"));
+        Assertions.assertTrue(match.matches("ab[secret]yz"));
+        Assertions.assertTrue(match.matches("ab[other]yz"));
+    }
 }

Reply via email to