Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DataUtils {
public static <E> E handleDataWithSecret(E data) {
E dataForLog = data;
if(data instanceof String && StringUtils.contains((String)data, "&secret=")){
dataForLog = (E) RegExUtils.replaceAll((String)data,"&secret=\\w+&","&secret=******&");
dataForLog = (E) RegExUtils.replaceAll((String)data,"&secret=\\w+","&secret=******");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 按参数边界遮蔽完整 secret 值

当待记录的请求参数中 secret 值包含 URL 编码或 -.+ 等非 \w 字符时,这个正则只会替换到第一个非 word 字符为止;例如 appid=wx&secret=abc%2Fdef 会被记录成 appid=wx&secret=******%2Fdef,仍然泄露后半段密钥。这里是日志脱敏逻辑,建议按参数边界匹配值(如直到下一个 & 或字符串结尾),而不是按 \w+ 匹配。

Useful? React with 👍 / 👎.

@augmentcode augmentcode Bot Jun 25, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleDataWithSecret currently only masks when the input contains "&secret=", so cases like "secret=abc123&..." (first param) or "?secret=abc123&..." won’t be desensitized and could still leak secrets in logs. Consider ensuring the match also works when secret is the first/only query parameter.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

}
return dataForLog;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ public void testHandleDataWithSecret() {
final String s = DataUtils.handleDataWithSecret(data);
assertTrue(s.contains("&secret=******&"));
}

@Test
public void testHandleDataWithSecretAtEnd() {
// Secret is the last parameter in the query string, so there is no trailing &
String data = "appid=wx123&secret=abc123";
final String s = DataUtils.handleDataWithSecret(data);
assertFalse(s.contains("abc123"), "Secret at the end of the string should be masked");
assertTrue(s.contains("secret=******"), "Secret should be replaced with asterisks");
}
}