fix(coding-agent): set auth file mode on creation

This commit is contained in:
Armin Ronacher
2026-06-03 00:32:54 +02:00
parent ba6e5298df
commit 135fb545f9

View File

@@ -45,6 +45,8 @@ type LockResult<T> = {
next?: string;
};
const AUTH_FILE_WRITE_OPTIONS = { encoding: "utf-8", mode: 0o600 } as const;
export interface AuthStorageBackend {
withLock<T>(fn: (current: string | undefined) => LockResult<T>): T;
withLockAsync<T>(fn: (current: string | undefined) => Promise<LockResult<T>>): Promise<T>;
@@ -66,7 +68,7 @@ export class FileAuthStorageBackend implements AuthStorageBackend {
private ensureFileExists(): void {
if (!existsSync(this.authPath)) {
writeFileSync(this.authPath, "{}", "utf-8");
writeFileSync(this.authPath, "{}", AUTH_FILE_WRITE_OPTIONS);
chmodSync(this.authPath, 0o600);
}
}
@@ -108,7 +110,7 @@ export class FileAuthStorageBackend implements AuthStorageBackend {
const current = existsSync(this.authPath) ? readFileSync(this.authPath, "utf-8") : undefined;
const { result, next } = fn(current);
if (next !== undefined) {
writeFileSync(this.authPath, next, "utf-8");
writeFileSync(this.authPath, next, AUTH_FILE_WRITE_OPTIONS);
chmodSync(this.authPath, 0o600);
}
return result;
@@ -153,7 +155,7 @@ export class FileAuthStorageBackend implements AuthStorageBackend {
const { result, next } = await fn(current);
throwIfCompromised();
if (next !== undefined) {
writeFileSync(this.authPath, next, "utf-8");
writeFileSync(this.authPath, next, AUTH_FILE_WRITE_OPTIONS);
chmodSync(this.authPath, 0o600);
}
throwIfCompromised();