Skip to content

Commit e85b25d

Browse files
fix(server): Codex shadow homes keep auth-like files private
Credential backups and alternate auth files such as auth.json.bak or auth-work.json were symlinked from the shared Codex home into every shadow home. Entries matching /^auth(?:$|[._-])/i are now treated as private, and any existing auth-like symlink in a shadow home is rejected, including dangling ones. Regular private files stay, author.json stays shared, and models_cache.json handling is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 25e9fe5 commit e85b25d

1 file changed

Lines changed: 40 additions & 16 deletions

File tree

‎apps/server/src/provider/Drivers/CodexHomeLayout.ts‎

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const KNOWN_SHARED_DIRECTORIES = [
2929
] as const;
3030

3131
const PRIVATE_ENTRY_NAMES = new Set(["auth.json", "models_cache.json"]);
32+
// Credential backups and alternate auth files (auth.json.bak, auth-work.json) stay per-home,
33+
// but unrelated names such as author.json remain shared.
34+
const AUTH_LIKE_ENTRY_NAME = /^auth(?:$|[._-])/i;
3235
// Finder maintains metadata separately for each directory, including shadow homes.
3336
const SHADOW_LOCAL_ENTRY_NAMES = new Set(["log", "memories", "tmp", ".DS_Store"]);
3437
// Codex creates these runtime locks itself when it starts in a shadow home before the shared
@@ -300,21 +303,38 @@ const ensureShadowAuthIsPrivate = Effect.fn("CodexHomeLayout.ensureShadowAuthIsP
300303
readonly effectiveHomePath: string;
301304
}): Effect.fn.Return<void, CodexShadowHomeError, Path.Path> {
302305
const path = yield* Path.Path;
303-
const entryName = "auth.json";
304-
const authPath = path.join(input.effectiveHomePath, entryName);
305-
const state = yield* readLinkState({
306-
...input,
307-
entryName,
308-
linkPath: authPath,
309-
});
310-
if (state._tag === "Symlink") {
311-
return yield* new CodexShadowHomePrivateEntrySymlinkError({
312-
sharedHomePath: input.sharedHomePath,
313-
effectiveHomePath: input.effectiveHomePath,
314-
entryName,
315-
path: authPath,
316-
});
317-
}
306+
const shadowEntryNames = yield* input.fileSystem.readDirectory(input.effectiveHomePath).pipe(
307+
Effect.catchTags({
308+
PlatformError: (cause) =>
309+
new CodexShadowHomeFileSystemError({
310+
sharedHomePath: input.sharedHomePath,
311+
effectiveHomePath: input.effectiveHomePath,
312+
operation: "readDirectory",
313+
path: input.effectiveHomePath,
314+
cause,
315+
}),
316+
}),
317+
);
318+
yield* Effect.forEach(
319+
shadowEntryNames.filter((entryName) => AUTH_LIKE_ENTRY_NAME.test(entryName)),
320+
Effect.fnUntraced(function* (entryName) {
321+
const authPath = path.join(input.effectiveHomePath, entryName);
322+
const state = yield* readLinkState({
323+
...input,
324+
entryName,
325+
linkPath: authPath,
326+
});
327+
if (state._tag === "Symlink") {
328+
return yield* new CodexShadowHomePrivateEntrySymlinkError({
329+
sharedHomePath: input.sharedHomePath,
330+
effectiveHomePath: input.effectiveHomePath,
331+
entryName,
332+
path: authPath,
333+
});
334+
}
335+
}),
336+
{ discard: true },
337+
);
318338
},
319339
);
320340

@@ -373,7 +393,11 @@ export const materializeCodexShadowHome = Effect.fn("materializeCodexShadowHome"
373393
);
374394
const entries = new Set<string>(KNOWN_SHARED_DIRECTORIES);
375395
for (const entryName of sharedEntryNames) {
376-
if (!PRIVATE_ENTRY_NAMES.has(entryName) && !SHADOW_LOCAL_ENTRY_NAMES.has(entryName)) {
396+
if (
397+
!PRIVATE_ENTRY_NAMES.has(entryName) &&
398+
!SHADOW_LOCAL_ENTRY_NAMES.has(entryName) &&
399+
!AUTH_LIKE_ENTRY_NAME.test(entryName)
400+
) {
377401
entries.add(entryName);
378402
}
379403
}

0 commit comments

Comments
 (0)