fix(coding-agent): set auth file mode on creation
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user