fix(browse): surface auto-cookie state read errors instead of swallowing

loadAutoCookieState treated every read failure as the benign corrupt-file
case and returned null silently. Split the file read from the JSON parse: a
read error (e.g. EACCES) now logs a warning — the device cookie won't restore
and that should be visible — while a JSON parse failure stays silent (a later
save overwrites it). Addresses a slop-scan default-return/filesystem finding.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
현성 2026-07-07 20:26:36 +09:00
parent 2f2ed32b46
commit 1404106293
1 changed files with 12 additions and 3 deletions

View File

@ -258,12 +258,21 @@ export function loadAutoCookieState(
): { cookies: Cookie[]; origins: [] } | null {
if (!isAutoCookiePersistEnabled()) return null;
const file = statePath(config);
let parsed: AutoCookieState;
let raw: string;
try {
if (!fs.existsSync(file)) return null;
parsed = JSON.parse(fs.readFileSync(file, 'utf-8')) as AutoCookieState;
raw = fs.readFileSync(file, 'utf-8');
} catch (err: any) {
// A read error here (e.g. EACCES) is NOT the benign corrupt-file case — the
// device cookie silently won't restore, so surface it rather than swallow.
console.warn(`[browse] auto-cookie state unreadable (${err?.code || err?.message}); starting without persisted cookies`);
return null;
}
let parsed: AutoCookieState;
try {
parsed = JSON.parse(raw) as AutoCookieState;
} catch {
return null; // corrupt — ignore (a later save will overwrite it)
return null; // corrupt JSON — ignore (a later save overwrites it)
}
if (!parsed || parsed.kind !== STATE_KIND || parsed.version !== STATE_VERSION) return null;
if (parsed.workspaceId !== computeProfileId(config)) return null;