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, so

View on GitHub (pinned to bed535e087)

Solutions

  1. Identify the masked token in the message and remove/replace that exact TWITTER_AUTH_TOKEN entry.
  2. Clear the stale cache keys 'twitter:cookie:<token>' and the lock key so a fresh exchange is attempted.
  3. Obtain a fresh auth_token cookie from a logged-in x.com session and update the env.
  4. 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

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


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/676a6d0270cad8b8. Report an issue: GitHub.