Adopt a single secure-by-default rule-set: authentication/authorization gates must fail closed, secret-bearing data must never be logged, and sandbox/file boundaries must be enforced with real paths and deny escape hatches.
Apply this checklist: 1) Auth/state mismatches must not proceed on implicit user dismissal
// Fail-closed auth callback example
if (authService.authNonce !== state) {
const result = await vscode.window.showWarningMessage(
`Could not verify auth state for ${uri.path}. Store token only if you started this sign-in.`,
{ modal: true },
"Store",
);
if (result !== "Store") return; // undefined/dismiss => cancel
}
2) Secrets must never appear in logs or error messages
origin (and ideally origin + pathname if you truly must keep path), stripping query/fragment/userinfo.// Secret-safe URL log pattern
function redactUrlForLog(url: string): string {
try {
const u = new URL(url);
return u.origin === "null" ? `${u.protocol}<redacted>` : u.origin;
} catch {
return "<invalid url>";
}
}
logger.info(`Opening browser: ${redactUrlForLog(rawUrl)}`);
3) Sandbox/file grants must be boundary-safe (fail closed)
realpath) and verify grants are inside the intended workspace.// Boundary-safe grant example (conceptual)
const realCwd = await realpath(cwd);
if (isHomeOrAncestor(realCwd) || isVolumeRoot(realCwd)) {
throw new Error("Refusing unsafe sandbox write root");
}
4) Ownership/handshake takeovers must be explicit
5) Avoid bypassable assumptions in security limits
If you can’t prove (1) fail-closed behavior, (2) secret-safe observability, and (3) boundary enforcement from code + tests, treat the change as insecure-by-default and require a redesign.