mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-22 04:38:24 +08:00
fix(security): redact sensitive values in storage command output
The browse `storage` command dumps all localStorage and sessionStorage as JSON. This can expose tokens, API keys, JWTs, and session credentials in QA reports and agent transcripts. Fix: redact values where the key matches sensitive patterns (token, secret, key, password, auth, jwt, csrf) or the value starts with known credential prefixes (eyJ for JWT, sk- for Stripe, ghp_ for GitHub, etc.). Redacted values show length to aid debugging: [REDACTED — 128 chars]
This commit is contained in:
@@ -289,7 +289,21 @@ export async function handleReadCommand(
|
|||||||
localStorage: { ...localStorage },
|
localStorage: { ...localStorage },
|
||||||
sessionStorage: { ...sessionStorage },
|
sessionStorage: { ...sessionStorage },
|
||||||
}));
|
}));
|
||||||
return JSON.stringify(storage, null, 2);
|
// Redact values that look like secrets (tokens, keys, passwords, JWTs)
|
||||||
|
const SENSITIVE_KEY = /token|secret|key|password|credential|auth|jwt|session|csrf|api.?key/i;
|
||||||
|
const SENSITIVE_VALUE = /^(eyJ|sk-|pk-|ghp_|gho_|github_pat_|xox[bpsa]-|Bearer\s)/;
|
||||||
|
const redacted = JSON.parse(JSON.stringify(storage));
|
||||||
|
for (const storeType of ['localStorage', 'sessionStorage'] as const) {
|
||||||
|
const store = redacted[storeType];
|
||||||
|
if (!store) continue;
|
||||||
|
for (const [key, value] of Object.entries(store)) {
|
||||||
|
if (typeof value !== 'string') continue;
|
||||||
|
if (SENSITIVE_KEY.test(key) || SENSITIVE_VALUE.test(value)) {
|
||||||
|
store[key] = `[REDACTED — ${value.length} chars]`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return JSON.stringify(redacted, null, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'perf': {
|
case 'perf': {
|
||||||
|
|||||||
Reference in New Issue
Block a user