{"record":{"id":"4f05c765e18336f4","repo":"DIYgod/RSSHub","slug":"invalid-cookie-4f05c7","errorCode":null,"errorMessage":"Invalid cookie","messagePattern":"Invalid cookie","errorType":"exception","errorClass":"ConfigNotFoundError","httpStatus":null,"severity":"error","filePath":"lib/routes/instagram/web-api/utils.ts","lineNumber":69,"sourceCode":"    let id = await cache.get(`instagram:getIdByUsername:${username}`);\n    let userInfoCache = await cache.get(`instagram:userInfo:${id}`);\n    userInfoCache = userInfoCache && typeof userInfoCache === 'string' ? JSON.parse(userInfoCache) : userInfoCache;\n\n    if (!userInfoCache) {\n        try {\n            const response = await ofetch.raw(`${baseUrl}/api/v1/users/web_profile_info/`, {\n                // cookieJar,\n                headers: {\n                    cookie: (await cookieJar.getCookieString(COOKIE_URL)) as string,\n                    ...((await getHeaders(cookieJar)) as unknown as Record<string, string>),\n                    // 'X-IG-WWW-Claim': (await cache.get('instagram:wwwClaimV2')) ?? undefined,\n                },\n                query: {\n                    username,\n                },\n            });\n            if (response.url.includes('/accounts/login/')) {\n                throw new ConfigNotFoundError('Invalid cookie');\n            }\n\n            webProfileInfo = response._data.data.user;\n            id = webProfileInfo.id;\n\n            await cache.set(`instagram:getIdByUsername:${username}`, id ?? '', 31_536_000); // 1 year since it will never change\n            await cache.set(`instagram:userInfo:${id}`, webProfileInfo);\n        } catch (error) {\n            if ((error as Error).message.includes(\"Cookie not in this host's domain\")) {\n                throw new ConfigNotFoundError('Invalid cookie');\n            }\n            throw error;\n        }\n    }\n\n    return userInfoCache || webProfileInfo;\n};\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/instagram/web-api/utils.ts#L51-L87","documentation":"Thrown as `ConfigNotFoundError('Invalid cookie')` in `getUserInfo` (web-api/utils.ts:68-70). After calling `GET /api/v1/users/web_profile_info/?username=...`, if the response URL contains `/accounts/login/` it means Instagram redirected the API call to the login page — i.e. the request was treated as unauthenticated. The cookie header supplied is invalid/missing for this endpoint.","triggerScenarios":"Calling the user-profile-info endpoint with a cookie that has expired or lacks the required session cookies; Instagram silently redirects unauthenticated API calls to `/accounts/login/` instead of returning 401.","commonSituations":"Cookie expired between the `checkLogin` probe and this call; cookie present but missing `sessionid`/`ds_user_id`; rate-limited/soft-logged-out session; server IP mismatch.","solutions":["Refresh `INSTAGRAM_COOKIE` with a current browser session.","Make sure the cookie string includes all required cookies (`sessionid`, `ds_user_id`, `csrftoken`, `ig_did`, `mid`, `ig_nrcb`).","Check the account is not temporarily restricted; clear the `instagram:getIdByUsername` / `instagram:userInfo` cache entries that may hold a stale/empty id."],"exampleFix":"// before: response.url.includes('/accounts/login/') -> throw\n// after: supply a complete, fresh cookie\nINSTAGRAM_COOKIE=sessionid=...; ds_user_id=...; csrftoken=...; ig_did=...; mid=...;","handlingStrategy":"try-catch","validationCode":"// none — detection is post-response (redirect URL). Pre-check cookie presence:\nif (!cookie) throw new ConfigNotFoundError('INSTAGRAM_COOKIE not set');","typeGuard":"const redirectedToLogin = (url: string) => url.includes('/accounts/login/');","tryCatchPattern":"try {\n  const res = await ofetch.raw(url, { headers: { cookie } });\n  if (redirectedToLogin(res.url)) throw new ConfigNotFoundError('Invalid cookie');\n} catch (e) { if (/Cookie not in this host/.test((e as Error).message)) throw new ConfigNotFoundError('Invalid cookie'); throw e; }","preventionTips":["Treat any redirect to /accounts/login/ as an auth failure.","Keep the cookie complete (all required IG cookies).","Clear cached empty ids when the cookie is refreshed."],"tags":["instagram","cookie","web-api","redirect-detection"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}