Repository navigation
fix(site): unify Chrome 144 headers, HTTP/2, cookie hygiene, t.co meta-refresh, and Douyin webid persistence - #197
Conversation
…a-refresh, and Douyin webid persistence Signed-off-by: chialecode <315431287+chialecode@users.noreply.github.com>
…transport-hygiene Signed-off-by: chialecode <315431287+chialecode@users.noreply.github.com> # Conflicts: # docs/ui.md # internal/site/douyin/auth.go # internal/site/douyin/client.go # internal/ui/login_view.go
|
Agent:已合并最新 origin/main(merge commit 5d22746,已含 DCO 签名),完整保留 #189(Douyin cookie_ttwidinfo_webid 同步)、#195(Cookie 粘贴引导与实时预检)和 #185 改动,并确保 Douyin 持久化默认 webid 与 ttwid 绑定的服务端同步 webid 严格隔离。 合并后重新验证:
|
…ter, harden meta-refresh and log redaction Signed-off-by: chialecode <315431287+chialecode@users.noreply.github.com>
|
Agent:已修复独立审查指出的 4 项问题并补充回归测试(commit
验证证据(零真实站点请求):
|
…transport-hygiene Signed-off-by: chialecode <315431287+chialecode@users.noreply.github.com>
|
Agent:独立代码审查(干净上下文,按 审查范围
关键核查项
未检查项(
|
…t-hygiene Signed-off-by: chialecode <315431287+chialecode@users.noreply.github.com>
…race Signed-off-by: chialecode <315431287+chialecode@users.noreply.github.com>
|
Agent:已将分支
验证
|
…-race and test ordering flakes (#209) Closes #208 ## 做了什么 修复 Ubuntu CI `go test -race` 暴露的 5 处已存在于 `main`(`f61d6866`)的仅限测试的并发/时序缺陷(不修改任何生产代码,不弱化任何非 `-race` 断言): 1. **`internal/player/player_test.go`、`internal/player/live_preview_test.go`**:引入基于 `sync.Mutex` 的 `syncTestClock` 辅助类型(保留 `time.Time` 单调时钟与时区语义),全面审计并替换 `internal/player/*_test.go` 中全部 3 处 `NullAudioSink.NowFunc` 未同步 `now` 闭包捕获: - `TestOpenLivePreviewGrowingHLSAndFLVFMP4AndDanmakuSuppressed`(`live_preview_test.go:242-243,280,306,335`,曾于 PR #197 CI run `46246425655` 触发 `-race` 失败) - `TestEndToEndLiveRecorderAndPlayerPreviewFinalizeWithoutHandleConflict`(`live_preview_test.go:658-659,670`,同类 `LoadLiveDecoder` + `runVideoWorker` 并发读写风险) - `TestPureAudioControllerClockSeekPreviewVolumeAndEOF`(`player_test.go:273-275,305,319,352`,统一使用同步假时钟消除未同步模式) 2. **`internal/service/preview_media_test.go:181`**:将 `TestStagePreviewMediaStreamingLimitCancelAndVideoFriendlyErrors` 的 `chunkSent := make(chan struct{})` 改为缓冲容量 1 的 `make(chan struct{}, 1)`,修复 HTTP 处理协程非阻塞发送早于测试主协程进入 `select` 时的丢唤醒超时(曾于 PR #194 CI run `46246187044` 失败)。 3. **`internal/library/race_disabled_test.go`、`internal/library/race_enabled_test.go`、`internal/library/batch_storage_test.go:368`**:沿用 PR #203 规范区分 `//go:build !race` 与 `//go:build race`;非 `-race` 保持严格 `2s` 预算,`-race` 下放宽至 `10s`,修复纯 Go SQLite 在 `-race` 插桩下查询 5,000 条记录约 `2.1s` 的超时误报(PR #194 run `46246187044` attempt 2 报 `2.077s`、本 PR run `46248609653` 报 `2.130s`)。 4. **`internal/download/weibo_download_test.go:1549`**:`waitForTaskTerminal` 在轮询到数据库终态的同时加锁确认 `mgr.activeRun[taskID]` 已清理,确保工作协程同步清理完 `activeProbeSite` 后才返回,修复 `TestManualTasksDuringBackoffRespectSingleProbeCapAndNotifyFailure` 紧随其后调用 `RetryActionable` 时因 `activeProbeSite` 尚未清除而跳过探测标记的时序竞态(本 PR run `46248609653`)。 5. **`internal/service/event_coalescing_and_lock_safety_test.go`**:`TestWeiboBackfillTierABatchCoalescesLibraryEvents` 两个子测试同时等待 `EventCacheQueueUpdated` 完成通知(严格在 `backfill.go:870-871` 的 `publishBackfillBatchLibraryChanged` 之后触发)再检查 `libEvents`,消除解锁后事件尚未发布即读取导致的 `published 0 EventLibraryChanged events` 时序竞态(本 PR run `46248609653`),零任意休眠且完全保留 `len(got) == 1` 严格断言。 未找到本地参考索引(`tools/checkdocs` 实测)。 ## 验证 - [x] `go test -count=3 ./internal/player`(退出码 `0`,`19.629s`,3 轮全通过) - [x] `go test -count=5 -run TestStagePreviewMediaStreamingLimitCancelAndVideoFriendlyErrors ./internal/service`(退出码 `0`,`0.760s`,5 轮全通过) - [x] `go test -count=3 -run TestStatisticsAuthorItemCountAndBytesWithViaAnd5000Items ./internal/library`(退出码 `0`,`1.001s`) - [x] `go test -count=3 -run TestManualTasksDuringBackoffRespectSingleProbeCapAndNotifyFailure ./internal/download`(退出码 `0`,`1.700s`) - [x] `go test -count=5 -run TestWeiboBackfillTierABatchCoalescesLibraryEvents ./internal/service`(退出码 `0`,`5.811s`) - [x] `go run ./tools/check`(退出码 `0`,`ALL CHECKS PASSED in 4m3.295s`,覆盖 `gofmt`、`go vet ./...`、`go test ./...`、依赖方向、`trace-server` Linux `amd64`/`arm64` 构建与 `GOOS=linux go vet ./...`、`tools/checkdocs`、`git diff --check HEAD`) - [x] GitHub Actions `repository-quality`(run `46251007067`,`13m15s`,含 Ubuntu `go test -race` 全部 48 包 0 竞态)、`Analyze (actions)`(`38s`)、`Analyze (go)`(`1m50s`)、`CodeQL`(`2s`)、`DCO`(`1s`)在当前头提交 `bbbd44cee04dd58826bc66c8b761392ac97cbf97` 全部通过 - [x] 独立审查覆盖 `bbbd44cee04dd58826bc66c8b761392ac97cbf97` 并通过(`#issuecomment-7254278140`,0 P0/P1/P2,可合并) - `go test -race`:`not-run`(本机 Windows 无 CGO 工具链),已由 Ubuntu CI `repository-quality`(run `46251007067`)全量验证通过。 - 推送说明:本次在独立 `git worktree` 工作树内执行,按 `LESSONS.md` 规则先单独完整通过 `go run ./tools/check` 后使用 `git push --no-verify` 推送,避免 `pre-push` 钩子注入 `GIT_DIR` 干扰 `tools/release` 测试仓库操作。 ## 风险 风险等级:低风险 - 仅修改/新增测试文件(共 8 个 `*_test.go` 文件),零生产代码变更,未删除或弱化任何非 `-race` 断言,不涉及高风险清单(`docs/dev-rules/workflow.md#high-risk`)。 每个提交都带 `Signed-off-by`(`git commit -s`)。 --------- Signed-off-by: chialecode <315431287+chialecode@users.noreply.github.com>
…t-hygiene Signed-off-by: chialecode <315431287+chialecode@users.noreply.github.com>
|
Agent:已将分支
验证
|
Signed-off-by: chialecode <315431287+chialecode@users.noreply.github.com>
Closes #183
做了什么
按 issue #183 统一补齐哔哩哔哩、抖音、微博、X 四个站点的浏览器请求头指纹一致性、HTTP/2 传输协商、跨站 Cookie 隔离、短链解析、
webid持久化与登录/远程风险提示:共享现代桌面 Chrome 浏览器配置(
internal/site纯 Go 标准库实现)internal/site/browser_profile.go:BrowserProfile、DeriveBrowserProfile(ua)、ApplyClientHints(http.Header)与 W3C Fetch 语义的DeriveSecFetchSite(referer, targetURL),严格遵守tools/check依赖规则(internal/site仅使用 Go 标准库)。Chrome/144.0.0.0(Windows NT 10.0; Win64; x64,DefaultUserAgent及 B 站/抖音/微博/X 同步),配套一致的Sec-Ch-Ua/Sec-Ch-Ua-Mobile: ?0/Sec-Ch-Ua-Platform: "Windows"。Sec-Ch-Ua*头部。a_bogus黄金向量测试通过,所有站点与查询指纹参数共享同一套派生逻辑。抖音(
internal/site/douyin/、internal/credential/、internal/service/)ReflowRoomInfo与CheckRoomsAlive对webcast.amemv.com设置guestNoCookie: true,确保.douyin.comCookie 绝不发往webcast.amemv.com(附回归测试断言Cookie == ""与Sec-Fetch-Site: cross-site)。ResolvePlayRedirect请求头:对/aweme/v1/play/改用独立的applyPlayRedirectHeaders(Accept: */*、Accept-Language: zh-CN,zh;q=0.9、Referer: https://www.douyin.com/、Sec-Fetch-Mode: no-cors、Sec-Fetch-Dest: video,移除Origin与 JSON/CORS 头;仅对*.douyin.com附带所需会话 Cookie 并在任何非douyin.com主机上显式剔除 Cookie)。webid:在credential.Record增加向后兼容的可选字段DouyinWebID string \json:"douyinWebId,omitempty"`(不改写 schema 版本,旧douyin.bin无缝读取),新增DouyinWebID/SaveDouyinWebID/EnsureDouyinWebID并在internal/service/backend.go(覆盖桌面端与internal/remoteserver/run.go)及douyin.NewClient/LoginWithCookie接入,重新粘贴 Cookie 时保留同一webid`。X(
internal/site/x/)Sec-Fetch-Site:将硬编码的Sec-Fetch-Site: same-origin替换为基于site.DeriveSecFetchSite的动态计算,使https://x.com/→https://api.x.com/1.1/account/settings.json发送same-site,https://x.com/→https://x.com/i/api/graphql/...发送same-origin。abs.twimg.com静态脚本请求头:fetchStaticAsset(含重定向每一跳)携带Referer: https://x.com/、来自浏览器配置的Sec-Ch-Ua*、Sec-Fetch-Site: cross-site、Sec-Fetch-Mode: no-cors、Sec-Fetch-Dest: script,同时继续严格剥离Cookie/Authorization/X-Csrf-Token/X-Twitter-Auth-Type/X-Client-Transaction-Id/Origin。t.coHTTP 200 HTML meta-refresh 与 JS fallback 支持:在 3xxLocation之外,支持有界读取(<= 64 KiB)HTTP 200 HTML 中的<meta http-equiv="refresh" content="...;URL=...">及location.replace("...")回退跳转,复用严格的 HTTPS、SSRF/白名单域名校验、零 Cookie 与 5 跳上限。微博(
internal/site/weibo/)weibo/client.go接入共享site.BrowserProfile与site.DeriveSecFetchSite,为/ajax/*与/tv/api/component补齐Sec-Fetch-Site、Sec-Fetch-Mode: cors、Sec-Fetch-Dest: empty与Sec-Ch-Ua*(未触碰微博扫码登录相关范围)。哔哩哔哩与媒体传输(
internal/site/bilibili/、internal/credential/、internal/download/、internal/live/)apiTransport/mediaTransport以及抖音/微博/X、下载与直播媒体http.Transport显式启用ForceAttemptHTTP2: true。Referer、Accept、Accept-Language、Sec-Fetch-*与 POSTOrigin:space.bilibili.com/<mid>、arc/search、feed/space、relation/followings、fav使用https://space.bilibili.com/<mid>/(无 mid 回退首页);api.live.bilibili.com使用https://live.bilibili.com/;wbi/view、playurl、player/wbi/v2与seg.so弹幕在已知bvid时使用https://www.bilibili.com/video/<bvid>/(DanmakuXML扩展向后兼容的可变参数bvid ...string);/correspond/1/...、b23.tv)发送 HTMLAccept与navigate/document/?1(b23.tv无Referer、Sec-Fetch-Site: none、无 Cookie),seg.so发送Accept: */*,JSON 接口发送application/json, text/plain, */*与cors/empty;cookie/refresh、confirm/refresh)附带Origin: https://www.bilibili.com。0..200ms可注入随机抖动(PacingJitterMax/PacingJitterFunc),单测保持确定性与快速执行。buvid3、buvid4、b_nut:在credential.AllowedCookieKeys放行可选字段buvid3、buvid4、b_nut(SESSDATA仍为必填),并在Store.RedactString与Manager.RedactString中对原始/URL 编码/JSON 形式全面脱敏,附哨兵防泄漏单测。登录页与远程设置风险提示文案(
internal/ui/、docs/ui.md)docs/ui.md§3.7–3.8(保留 X 风险提示框全部必检短语与布局约束)。验证
go run ./tools/check— ALL CHECKS PASSED(gofmt -l345ms、go vet ./...1.583s、go test ./...全仓全部包通过含internal/ui237.558s、dependency direction2.826s、trace-server linux build26.146s、tools/checkdocs1.905s、git diff --check HEAD149ms)go run ./tools/uishots -out artifacts/uishots— all passed(生成并断言通过全部 381 张截图,含login-x风险提示布局与全部 10 项文案断言)repository-quality(建 PR 后由 GitHub Actions 自动运行)go run ./tools/package -install并供用户实测(由协调器在独立审查后安排)not-run: 真实站点请求(本次实现与测试严格零真实站点请求,全部采用单元测试、合成样本、本地回环httptest与ui.NewTester)not-run:go test -race ./...(本机门禁与无 cgo Windows 构建环境默认CGO_ENABLED=0)git worktree中执行且本地已先跑通go run ./tools/check,按LESSONS.mdchore(deps): bump golang.org/x/image from 0.47.0 to 0.48.0 in the minor-and-patch group #9 使用git push --no-verify -u origin fix/183-site-headers-transport-hygiene以避开pre-push中GIT_DIR与tools/release测试冲突。风险
风险等级:高风险(已加
risk:high标签,原因:修改了internal/credential/凭证白名单、脱敏规则与Record可选持久化字段douyinWebId;向后兼容旧bilibili.bin/douyin.bin,无结构版本变更、无通道隔离变更,需经独立审查与审核前本机trace-dev安装并由用户测试后合并)。每个提交都带
Signed-off-by(git commit -s)。