Skip to content

fix(wopan): initialize tokens and set dispatcher user agent (close #9677) - #9678

Closed
chenweiliang6 wants to merge 2 commits into
AlistGo:mainfrom
chenweiliang6:fix/wopan-mount
Closed

chenweiliang6 wants to merge 2 commits into
AlistGo:mainfrom
chenweiliang6:fix/wopan-mount

Conversation

@chenweiliang6

Copy link
Copy Markdown

问题现象

联通云盘存储无法初始化,报错:

  • failed init storage / failed to list objs: request failed with status: 403 Forbidden
  • 只填 refresh_token 时:crypto/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 请求带浏览器 UA
    • access token 缺失或短于 16 位时先刷新并校验刷新结果
    • 先 InitData() 再 FamilyUserCurrentEncode(),错误带阶段前缀,透传 ctx
  • refresh_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 通过
  • 尚未用真实账号做端到端验证(手头无 token),建议合并后用真实账号跑一次

waylon.chen and others added 2 commits October 21, 2026 17:57
@okatu-loli

Copy link
Copy Markdown
Collaborator

fix by #9674

@okatu-loli okatu-loli closed this Oct 21, 2026
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.

2 participants