DIYgod/RSSHub · error · ConfigNotFoundError
Twitter cookie for token ${auth?.token?.replace(/(\w{8})(\w+
Error message
Twitter cookie for token ${auth?.token?.replace(/(\w{8})(\w+)/, (_, v1, v2) => v1 + '*'.repeat(v2.length))} is not valid What it means
ConfigNotFoundError thrown when an auth token was found (getAuth returned one) but token2Cookie(auth.token) could not produce a usable cookie jar. RSSHub caches the deserialized cookie per token; if the cached cookie is missing/corrupt or the token-to-cookie exchange failed, it cannot build the CookieAgent dispatcher and rejects the request rather than sending an unauthenticated call.
Source
Thrown at lib/routes/twitter/api/web-api/utils.ts:125
logger.debug(`twitter debug: got twitter cookie for token ${auth?.token}`);
if (typeof cookie === 'string') {
cookie = JSON.parse(cookie);
}
const jar = CookieJar.deserializeSync(cookie as any);
const agent = proxy.proxyUri
? new ProxyAgent({
uri: proxy.proxyUri,
}).compose(HttpCookieAgentCookie({ jar }))
: new CookieAgent({ cookies: { jar } });
if (proxy.proxyUri) {
logger.debug(`twitter debug: Proxying request: ${requestUrl}`);
}
dispatchers = {
jar,
agent,
};
} else if (auth) {
throw new ConfigNotFoundError(`Twitter cookie for token ${auth?.token?.replace(/(\w{8})(\w+)/, (_, v1, v2) => v1 + '*'.repeat(v2.length))} is not valid`);
}
const jsonCookie = dispatchers
? Object.fromEntries(
dispatchers.jar
.getCookieStringSync(url)
.split(';')
.map((c) => Cookie.parse(c)?.toJSON())
.map((c) => [c?.key, c?.value])
)
: {};
// Use undici.fetch directly instead of ofetch.raw to preserve the CookieAgent
// dispatcher. Two layers drop it in the normal path:
// 1. ofetch does not forward `dispatcher` to its internal fetch() call
// 2. wrappedFetch (request-rewriter) does `new Request(input, init)` which
// discards non-standard options like `dispatcher`
// Additionally, setting `cookie` header manually doesn't work either because
// the Fetch spec treats `cookie` as a forbidden header name, soView on GitHub (pinned to bed535e087)
Solutions
- Identify the masked token in the message and remove/replace that exact TWITTER_AUTH_TOKEN entry.
- Clear the stale cache keys 'twitter:cookie:<token>' and the lock key so a fresh exchange is attempted.
- Obtain a fresh auth_token cookie from a logged-in x.com session and update the env.
- Restart RSSHub after updating config.
Example fix
// before: stale/revoked token in env // TWITTER_AUTH_TOKEN=oldtoken // after // TWITTER_AUTH_TOKEN=newtoken (re-extracted from x.com cookie 'auth_token')
Defensive patterns
Strategy: retry
Validate before calling
// Before the call, confirm a cached cookie exists for at least one token.
async function anyValidCookie(tokens: string[], cache): Promise<boolean> {
for (const t of tokens) { if (await cache.get(`twitter:cookie:${t}`)) return true; }
return false;
} Type guard
function isValidCookieJar(serialized: unknown): boolean {
try { return !!serialized && typeof (serialized as any).cookies !== 'undefined'; }
catch { return false; }
} Try / catch
try { await twitterGot(url, params); }
catch (e) {
if (/cookie .* is not valid/.test(String(e))) {
// evict the bad token's cache and retry with the next token
await cache.del(`twitter:cookie:${masked}`);
return retryWithNextToken();
}
throw e;
} Prevention
- Keep more than one auth token so a single bad cookie does not take the route down.
- Monitor for repeated 'cookie is not valid' for the same token and rotate it proactively.
- Ensure the cache backend has enough memory/TTL that cookie entries are not prematurely evicted.
When it happens
Trigger: auth.token resolves but the cached 'twitter:cookie:<token>' entry was evicted, expired, or stored a malformed JSON; token2Cookie returned falsy; the login() fallback path that used to repair cookies is commented out, so there is no automatic recovery. The masked token id is logged to help identify which configured token is bad.
Common situations: Cache backend was flushed between requests; the token's cookie was never successfully minted (first use after token rotation); Redis/memory cache evicted the entry under memory pressure; token revoked by Twitter so the exchange returns nothing.
Related errors
- No valid Twitter token found
- 未配置 Cookie 或 Authorization。请检查配置。
- Invalid username (or email) or password for nhentai torrent
- Baidu Tieba RSS is disabled due to the lack of <a href="http
- 缺少对应 loginUid 的 Bilibili 用户登录后的 Cookie 值 <a href="https://do
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/676a6d0270cad8b8.
Report an issue: GitHub.