{"record":{"id":"97101ce76c0026f0","repo":"DIYgod/RSSHub","slug":"baidu-security-verification-required-the-cookie-m","errorCode":null,"errorMessage":"Baidu security verification required. The cookie may be expired or invalid. Please update your BAIDU_COOKIE.","messagePattern":"Baidu security verification required\\. The cookie may be expired or invalid\\. Please update your BAIDU_COOKIE\\.","errorType":"exception","errorClass":"Error","httpStatus":503,"severity":"error","filePath":"lib/routes/baidu/tieba/common.ts","lineNumber":33,"sourceCode":"export function parseBaiduCookies(cookieStr: string): Array<{ name: string; value: string; domain: string; path: string }> {\n    return cookieStr\n        .split(';')\n        .map((c) => Cookie.parse(c.trim()))\n        .filter((c): c is Cookie => Boolean(c?.key))\n        .map((c) => ({\n            name: c.key,\n            value: c.value,\n            domain: '.tieba.baidu.com',\n            path: '/',\n        }));\n}\n\n/**\n * 检查 HTML 内容是否包含百度安全验证页面\n */\nexport function checkSecurityVerification(html: string): void {\n    if (html.includes('安全验证') || html.includes('百度安全验证')) {\n        throw new Error('Baidu security verification required. The cookie may be expired or invalid. Please update your BAIDU_COOKIE.');\n    }\n}\n\n/**\n * 使用 Playwright 获取贴吧页面内容\n * 包含统一的 cookie 设置、安全验证检查和缓存逻辑\n * 带有重试机制处理瞬态错误\n */\nexport async function getTiebaPageContent(\n    url: string,\n    cacheKey: string,\n    options: {\n        waitForSelector?: string;\n        timeout?: number;\n        retries?: number;\n    } = {}\n): Promise<string> {\n    const cookie = config.baidu.cookie;","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/baidu/tieba/common.ts#L15-L51","documentation":"Thrown by checkSecurityVerification in the Baidu Tieba common helpers after a fetched page's HTML is detected as a Baidu security-verification (anti-bot) wall. The check matches the substrings '安全验证' or '百度安全验证', which appear when BAIDU_COOKIE is expired, invalid, or absent, signalling the request was challenged rather than served real content.","triggerScenarios":"getTiebaPageContent (or any caller of checkSecurityVerification) fetches a Tieba page and the returned HTML contains the security-verification markers, typically after Playwright loaded the page with an expired/invalid BAIDU_COOKIE.","commonSituations":"BAIDU_COOKIE expired since last refresh; cookie set but not for the .tieba.baidu.com domain; Baidu tightened its anti-bot heuristics; running from a datacenter IP that Baidu flags.","solutions":["Refresh BAIDU_COOKIE by logging into tieba.baidu.com in a browser and copying a fresh cookie string (must include BDUSS) into the BAIDU_COOKIE env var.","Ensure the cookie's domain scope covers .tieba.baidu.com and that you are not being challenged due to IP reputation (try a residential egress).","If using Playwright, confirm waitForSelector is finding real thread content rather than the verification page; consider raising retries or adding a cookie-rotation strategy."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"function looksLikeSecurityWall(html: string): boolean {\n    return html.includes('安全验证') || html.includes('百度安全验证');\n}\n// before fetching heavily, peek the page; if true, refresh cookie first","typeGuard":null,"tryCatchPattern":"try {\n    return await getTiebaPageContent(url, cacheKey, { retries: 3 });\n} catch (e) {\n    if (e instanceof Error && /security verification|BAIDU_COOKIE/i.test(e.message)) {\n        // refresh BAIDU_COOKIE out-of-band, then retry once\n    }\n    throw e;\n}","preventionTips":["Keep BAIDU_COOKIE fresh; rotate before it expires rather than after.","Monitor for the verification substrings and alert so expiry is detected proactively.","Run from a stable egress IP to reduce anti-bot triggers."],"tags":["baidu","tieba","anti-bot","cookie","config","playwright"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}