Repository navigation
Description
What happened
When codex-unlock runs as root while HOME still points to a regular user's home (for example an elevated shell that preserves HOME), the automatic update refresh creates the update cache inside that user's home owned by UID 0. Afterwards, update checks by the owning user fail permanently.
The cache location is derived from XDG_CACHE_HOME or homedir() ($HOME). ensurePrivateDirectory creates it with mkdirSync(..., { recursive: true, mode: 0o700 }) and compares ownership only with the current UID, so a UID 0 process accepts a root-owned directory inside another user's home.
Reproduced in an isolated Linux container (no network, no host mounts, synthetic home, empty CODEX_HOME), using docker exec --user 0 and --user 1000:1000 with the same HOME to model "elevated process with preserved HOME". sudo itself was not exercised.
| Scenario | Result |
|---|---|
A. User's ~/.cache exists (UID 1000, 0700); UID 0 runs interactive list |
Refresh child creates ~/.cache/codex-unlock as UID 0/0700. As UID 1000, two refreshes return cache_directory_is_unsafe with no fetch; check-update --json exits 3 with update check failed: cache_directory_is_unsafe |
B. ~/.cache does not exist; same sequence |
Both ~/.cache and ~/.cache/codex-unlock are created as UID 0/0700; UID 1000 gets EACCES and cache_directory_unavailable |
| C. Control: UID 1000 only | Both refreshes updated, cache owned by UID 1000 |
D. Control: UID 0, non-interactive list |
No cache created (refresh is scheduled only for interactive runs) |
In scenario B, other XDG tools of that user are also affected because ~/.cache itself becomes root-owned. list --json as the user kept working (exit 0) in all scenarios.
What you expected
An elevated process does not create or modify cache directories in another user's home. The update cache still fails closed for unsafe ownership, but the automatic notice/refresh path does not cause that state.
Environment
codex-unlock0.4.0 at6227e6c(src/update.tsandsrc/cli.tsidentical to the v0.4.0 release commit)- Linux aarch64 container, Node.js 24,
node:24-bookworm-slim
Source evidence
- Cache root from
XDG_CACHE_HOMEorhomedir():Lines 271 to 275 in 6227e6c
userHome: string = homedir(), ): UpdateCacheLocation { const configured = environment.XDG_CACHE_HOME; const root = configured && isAbsolute(configured) ? configured : join(userHome, ".cache"); const directory = join(root, "codex-unlock"); - Recursive creation and current-UID-only ownership check:
Lines 180 to 188 in 6227e6c
function ensurePrivateDirectory(path: string, uid: number): string | null { try { mkdirSync(path, { recursive: true, mode: 0o700 }); const initial = lstatSync(path); if ( !initial.isDirectory() || initial.isSymbolicLink() || initial.uid !== uid ) { - Automatic refresh from interactive commands:
Lines 257 to 262 in 6227e6c
function finishAutomaticAdvisory(advisory: PreparedUpdateAdvisory): void { emitHumanUpdateNotice(advisory.humanNotice); if (advisory.scheduleRefresh) { scheduleUpdateRefresh({ cliPath: process.argv[1] }); } } - Detached refresh child inherits the environment:
Lines 801 to 814 in 6227e6c
export function scheduleUpdateRefresh( options: ScheduleUpdateRefreshOptions, ): boolean { try { const spawnImpl = options.spawnImpl ?? spawn; const child = spawnImpl( options.executable ?? process.execPath, [options.cliPath, UPDATE_REFRESH_ARG], { detached: true, stdio: "ignore", env: options.environment ?? process.env, }, );
Acceptance criteria
- When running as UID 0 (or when the resolved cache root or home is not owned by the current UID), automatic update notices and refreshes are skipped without creating directories.
- Explicit
check-updatein that situation fails with a clear reason instead of creating directories in another user's home. - Existing cache directories are never automatically
chown/chmod-repaired. - Tests cover UID 0 with a foreign-owned
HOME, with and without an existing~/.cache.
Scope and limitations
- Requires the user to run the tool with elevated privileges while
HOMEis preserved; no privilege escalation is involved. How often commonsudoconfigurations preserveHOMEwas not measured. - Fails closed: the cache is rejected rather than trusted, and diagnostic commands are unaffected.
Checked
- security: specify update-cache privacy and failure isolation #28 specified cache privacy and failure isolation, fix: a FIFO at the update cache path hangs list, inspect, and unlock #57 covers a FIFO at the cache path, and fix: explicit check-update fails when the cache directory is not writable #62 covers explicit
check-updatewith an unwritable cache directory; none covers elevated runs creating foreign-owned cache directories.
Activity
fix: harden update cache boundary