Skip to content

fix(route/zhihu): auto-fetch __zse_ck when absent from ZHIHU_COOKIES#21321

Merged
TonyRL merged 1 commit intoDIYgod:masterfrom
DzmingLi:fix/zhihu-auto-fetch-zse-ck
Mar 7, 2026
Merged

fix(route/zhihu): auto-fetch __zse_ck when absent from ZHIHU_COOKIES#21321
TonyRL merged 1 commit intoDIYgod:masterfrom
DzmingLi:fix/zhihu-auto-fetch-zse-ck

Conversation

@DzmingLi
Copy link
Contributor

@DzmingLi DzmingLi commented Mar 6, 2026

Involved Issue / 该 PR 相关 Issue

Close #

Example for the Proposed Route(s) / 路由地址示例

NOROUTE

New RSS Route Checklist / 新 RSS 路由检查表

  • New Route / 新的路由
  • Anti-bot or rate limit / 反爬/频率限制
    • If yes, do your code reflect this sign? / 如果有, 是否有对应的措施?
  • Date and time / 日期和时间
    • Parsed / 可以解析
    • Correct time zone / 时区正确
  • New package added / 添加了新的包
  • `Puppeteer`

Note / 说明

When ZHIHU_COOKIES is configured, the if branch in getSignedHeader sends the full cookie string as-is, including a potentially stale __zse_ck. This token is embedded in Zhihu's static JS (static.zhihu.com/zse-ck/v3.js) and rotates periodically. When it expires, routes that scrape HTML pages (e.g. /zhihu/posts/people/:id) return 403, while API-only routes (e.g. /zhihu/people/answers/:id) are unaffected because they only rely on the dynamically computed x-zse-96 header.

This PR adds a fallback: if __zse_ck is absent from ZHIHU_COOKIES, fetch it automatically from Zhihu's public static JS. The value is site-wide (not user-specific) and requires no login. Users can now omit __zse_ck from ZHIHU_COOKIES and it will be fetched and cached automatically. Existing configs that include __zse_ck are unchanged.

When ZHIHU_COOKIES is configured without __zse_ck, automatically fetch
the value from Zhihu's public static JS (static.zhihu.com/zse-ck/v3.js).

__zse_ck is a site-wide token (not user-specific) that Zhihu embeds in
a static JS file and rotates periodically. When it expires, routes that
scrape HTML pages (e.g. /zhihu/posts/people/:id) return 403, while
API-only routes are unaffected.

Users can now omit __zse_ck from ZHIHU_COOKIES and it will be fetched
and cached automatically, eliminating manual cookie rotation for this
token. Existing configs that include __zse_ck are unchanged.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

Auto Review

No clear rule violations found in the current diff.

@TonyRL TonyRL merged commit 5469b02 into DIYgod:master Mar 7, 2026
37 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants