{"record":{"id":"59e2d37a93b72108","repo":"jackwener/OpenCLI","slug":"pixiv-phpsessid-prefix-unparseable","errorCode":null,"errorMessage":"Pixiv PHPSESSID prefix unparseable","messagePattern":"Pixiv PHPSESSID prefix unparseable","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/pixiv/auth.js","lineNumber":44,"sourceCode":"      }\n      const r = await fetch('/ajax/user/extra', { credentials: 'include', headers: { Accept: 'application/json' } });\n      if (r.status === 401 || r.status === 403) {\n        return { kind: 'auth', detail: 'Pixiv /ajax/user/extra HTTP ' + r.status };\n      }\n      if (!r.ok) return { kind: 'http', httpStatus: r.status };\n      const d = await r.json();\n      if (d?.error) return { kind: 'auth', detail: 'Pixiv /ajax/user/extra error=true — anonymous' };\n      const phpSess = (document.cookie.split('; ').find(c => c.startsWith('PHPSESSID=')) || '').split('=')[1] || '';\n      const uid = phpSess.split('_')[0] || '';\n      if (!uid) {\n        return { kind: 'auth', detail: 'Pixiv PHPSESSID prefix unparseable' };\n      }\n      return { ok: true, user_id: uid, name: '' };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('pixiv.net', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from Pixiv ajax`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`Pixiv whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Pixiv probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, name: probe.name };\n}\n\nregisterSiteAuthCommands({\n  site: 'pixiv',\n  domain: 'pixiv.net',\n  loginUrl: 'https://accounts.pixiv.net/login',\n  columns: ['user_id', 'name'],\n  quickCheck: hasPixivSessionCookie,\n  verify: verifyPixivIdentity,\n  poll: async (page) => {\n    if (!await hasPixivSessionCookie(page)) {\n      throw new AuthRequiredError('pixiv.net', 'Waiting for Pixiv PHPSESSID cookie');\n    }\n    return verifyPixivIdentity(page);","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pixiv/auth.js#L26-L62","documentation":"Inside the in-page probe, after the global-data meta tag and /ajax/user/extra both fail to yield a user id, the code parses the PHPSESSID cookie's `<uid>_` prefix to identify the user. If that prefix is empty/unparseable, the probe returns kind='auth' with detail 'Pixiv PHPSESSID prefix unparseable' and verifyPixivIdentity throws AuthRequiredError — the session cookie exists but doesn't identify a logged-in user.","triggerScenarios":"PHPSESSID present but its value lacks a numeric underscore prefix (anonymous/bare-hash session cookie), while the global-data meta tag is absent (pixiv A/B test, page variant, or SPA change) and /ajax/user/extra returns a non-error anonymous payload.","commonSituations":"Login half-completed: anonymous cookie set before the authenticated one; cookie manually copied from an anonymous browsing session; pixiv changed the global-data meta tag so the fallback path runs; regional/logged-out pixiv variant serving no global-data.","solutions":["Complete the pixiv login flow again so a properly `<uid>_hash`-shaped PHPSESSID is issued.","Delete the stale anonymous PHPSESSID cookie for pixiv.net, then log in fresh.","Check whether pixiv removed the `global-data` meta tag and update the probe to rely on /ajax/user/extra user data.","Verify logged-in state in the browser before running auth-required pixiv commands."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const sess = (document.cookie.split('; ').find(c => c.startsWith('PHPSESSID=')) || '').split('=')[1] || '';\nif (!/^\\d+_.+/.test(sess)) {\n  // anonymous or malformed session — trigger a fresh login before probing identity\n  await relogin();\n}","typeGuard":"function isAuthedPixivSession(phpsessid) {\n  return typeof phpsessid === 'string' && /^\\d+_.+/.test(phpsessid);\n}","tryCatchPattern":"try {\n  await pixivWhoAmI();\n} catch (err) {\n  if (String(err.message).includes('PHPSESSID prefix unparseable')) {\n    await clearCookie('PHPSESSID', 'https://www.pixiv.net');\n    await interactiveLogin('https://accounts.pixiv.net/login');\n    await pixivWhoAmI();\n  } else throw err;\n}","preventionTips":["Complete the login flow fully; do not interrupt accounts.pixiv.net mid-sign-in.","Clear stale anonymous PHPSESSID cookies before logging in.","Prefer reading the user id from /ajax/user/extra rather than the cookie prefix when available."],"tags":["pixiv","auth","cookie","parsing"],"backgroundTag":"missing-auth-cookie","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}