Skip to content

Mask secret query parameter when it is the last parameter#4055

Open
vasiliy-mikhailov wants to merge 1 commit into
binarywang:developfrom
vasiliy-mikhailov:fix/datautils-mask-trailing-secret
Open

Mask secret query parameter when it is the last parameter#4055
vasiliy-mikhailov wants to merge 1 commit into
binarywang:developfrom
vasiliy-mikhailov:fix/datautils-mask-trailing-secret

Conversation

@vasiliy-mikhailov

Copy link
Copy Markdown

DataUtils.handleDataWithSecret masks the secret value in a query string before it is logged, but the regex &secret=\w+& requires a trailing &. When secret is the last parameter — e.g. appid=wx123&secret=abc123 — there is no trailing &, so the value is not masked and the secret is exposed in log output.

This drops the trailing-& requirement (&secret=\w+&secret=******), so the value is masked regardless of its position. The middle-parameter case is unchanged: ...&secret=xxx&grant_type=... still becomes ...&secret=******&grant_type=....

Adds a regression test testHandleDataWithSecretAtEnd that fails before the change and passes after.

handleDataWithSecret masks the secret value before logging, but the regex &secret=\w+& requires a trailing &. When secret is the last query parameter (e.g. appid=wx123&secret=abc123) there is no trailing &, so it is not masked and leaks in logs. Drop the trailing-& requirement so the value is masked regardless of position; the middle-parameter case is unchanged. Adds a regression test.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 77c9cc6a6d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant