Repository navigation
fix(wopan): initialize tokens and set dispatcher user agent (close #9677) - #9678
Closed
chenweiliang6 wants to merge 2 commits into
Closed
chenweiliang6 wants to merge 2 commits into
chenweiliang6 wants to merge 2 commits into
Conversation
…istGo#9677) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collaborator
|
fix by #9674 |
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.
问题现象
联通云盘存储无法初始化,报错:
failed init storage/failed to list objs: request failed with status: 403 Forbiddencrypto/aes: invalid key size 0值得注意的是:同一账号下上传一直正常,只有初始化/列目录失败。
根因分析
1. dispatcher 请求不带浏览器 User-Agent → HTTP 403
wopan-sdk-go的WithUA/SetUA只把默认浏览器 UA 存进私有字段w.ua(仅upload2C上传路径使用),其余所有 dispatcher 请求(FamilyUserCurrentEncode、QueryAllFiles等)都以 resty 默认的go-resty/...UA 发出,被联通云盘边缘 WAF 直接拦截返回 403。已实测验证:同一请求 go-resty UA → 403,浏览器 UA → 正常响应。这也解释了为什么上传一直正常(upload2C 显式带 UA)。2. 初始化顺序错误 →
crypto/aes: invalid key size 0旧
Init先调FamilyUserCurrentEncode()再刷新 token。wohome 通道请求体用accessToken[:16]做 AES 密钥加密,access token 为空时密钥长度为 0。协议本身没有变化:已抓包核验
pan.wo.cn网页端当前仍使用相同的 dispatcher 地址、client secret、IV 和签名算法。修复方案
Init拆出initClient(ctx):d.client.SetUserAgent(wopan.DefaultUA)写入底层 resty client,保证所有 dispatcher 请求带浏览器 UAInitData()再FamilyUserCurrentEncode(),错误带阶段前缀,透传ctxrefresh_token不再标记必填,refresh token 或 access token 填其一即可不升级
wopan-sdk-go:v0.2.x 的SetUA仍然只写字段,升级修不了 403,还会引入无关 API 变化。测试
TestInitCredentials(drivers/wopan/driver_test.go),覆盖 6 种凭据组合(仅 refresh / 短 access + refresh / 双 token / 仅 access / 双空 / 仅短 access),断言:每个 dispatcher 请求 UA 必须等于wopan.DefaultUA、需要刷新时AppRefreshToken必须是第一个请求、刷新后 token 正确回写、凭据不合法时不发任何请求直接报错SetUserAgent后测试按预期失败,报错与用户反馈的 403 完全一致go build ./...与go test ./drivers/wopan/ -count=1通过