Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Token refresh still has credential-safety and sensitive-logging gaps.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
组件 Token 刷新错误日志泄露敏感凭证 · New
What changed in this PR
This PR protects miniapp and open-platform code2Session credentials from URL, exception, and SDK log leakage.
Changes:
- Adds UTF-8 parameter encoding and exception sanitization.
- Updates login, token refresh, and sensitive-request logging.
- Adds cross-client security tests and test logging configuration.
Review findings: token refresh credentials remain unencoded in the miniapp flow, and the open-platform POST token-refresh branch can still log sensitive error content.
| File | Description |
|---|---|
weixin-java-open/src/test/resources/testng.xml |
Registers open-platform security tests |
weixin-java-open/src/test/java/me/chanjar/weixin/open/api/impl/WxOpenCode2SessionSecurityTest.java |
Tests open-platform login security |
weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java |
Updates login API documentation |
weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceAbstractImpl.java |
Protects sensitive-request logging |
weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java |
Encodes parameters and sanitizes errors |
weixin-java-open/pom.xml |
Adds test dependencies and logging configuration |
weixin-java-miniapp/src/test/resources/testng.xml |
Registers miniapp security tests |
weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaCode2SessionSecurityTest.java |
Tests miniapp login security |
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java |
Updates login API documentation |
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java |
Protects login parameters, errors, and logs |
weixin-java-miniapp/pom.xml |
Configures test logging |
weixin-java-common/src/test/resources/testng.xml |
Registers common utility tests |
weixin-java-common/src/test/java/me/chanjar/weixin/common/util/http/SensitiveRequestUtilsTest.java |
Tests encoding and exception sanitization |
weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SensitiveRequestUtils.java |
Provides encoding and sanitization utilities |
pom.xml |
Centralizes test logging versions |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+276
to
+277
| log.warn("即将重新获取新的access_token,错误代码:{},错误信息:{}", error.getErrorCode(), | ||
| WxOpenServiceAbstractImpl.isSensitiveRequest(uri) ? "[redacted]" : error.getErrorMsg()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

普通小程序和开放平台代小程序登录直接拼接
jsCode等查询参数,特殊字符会改变 URL 结构或使 HTTP 客户端抛出包含凭证的异常;SDK 成功、错误和 token 刷新日志也可能输出请求或响应中的凭证。本 PR 对两个登录入口的原始参数逐值进行 UTF-8 编码,并对向外传播的异常建立安全边界:保留微信错误码和栈帧,移除原始消息、响应 JSON、cause 和 suppressed 异常。登录、开放平台获取 component token,以及小程序提取 access token 的 SDK 日志不再输出原始凭证数据。
兼容性与范围
get → execute扩展链、HTTP 客户端选择、API host/代理配置、token 刷新、系统繁忙重试和多账号切换。get(String, String)的已序列化查询串,不修改四种公共 GET 执行器的契约;普通登录继续沿用原 token 流程。session_key)不做脱敏。保留两个入口原有的 null 处理差异。WxRuntimeException,已更新 Javadoc。验证
新增测试已加入三个模块默认 TestNG suite,全部使用假凭证和本地服务,不调用微信:
+&=#?%、中文、非 BMP Unicode、空串和 null。受影响模块及依赖的默认套件:128 项通过,0 失败、0 跳过(common 24、mp 72、miniapp 9、open 23)。JDK 17 编译为 Java 8 目标,测试进程使用本机 Temurin 8u422:
另已通过定向
clean test与git diff --check。本机 Corretto 17 的本地 HttpServer 初始化出现Unable to establish loopback connection,因此未将 Windows/JDK 17 的完整测试执行计为通过;Java 8 下四客户端本地服务测试成功。未执行真实微信联调或全仓库测试。目标分支:
develop,遵循CONTRIBUTING.md的 Fork/PR 流程。