From 189710faac3fc551dd7de51362ca2c871f410023 Mon Sep 17 00:00:00 2001 From: Hyunwoo Park Date: Sat, 18 Jul 2026 16:46:11 +0900 Subject: [PATCH] fix: isolate Electron runtime temp files per user --- docs/troubleshooting.md | 1 + launcher/start.sh.template | 15 +++++++++++++ tests/scripts_smoke.sh | 43 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index c39f17acd..14087bad0 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -6,6 +6,7 @@ | Blank window | Check whether the configured webview port is already in use: `ss -tlnp \| grep -E '5175\|5176'` | | `ERR_CONNECTION_REFUSED` on the webview port | Ensure `python3` works and the configured port is free | | Stuck on Codex logo splash | Check `~/.cache/codex-desktop/launcher.log`; another process may be serving the webview port | +| A second launch opens another app instance, or Remote Control immediately turns itself off with `EACCES ... /tmp/codex-ipc/ipc-.sock` in the logs | Update and fully restart Codex Desktop. The launcher gives Electron a private default `TMPDIR` under `$XDG_RUNTIME_DIR`, preventing another Linux user from owning the shared IPC directory. An explicitly configured `TMPDIR` remains unchanged. | | `CODEX_CLI_PATH` error | Reopen the app to retry automatic CLI install, or install manually with `npm i -g --include=optional @openai/codex` / `npm i -g --include=optional --prefix ~/.local @openai/codex` | | `Missing optional dependency @openai/codex-linux-x64` or malformed tool calls after a self-managed npm CLI install | Reinstall with optional dependencies: `npm i -g --include=optional @openai/codex`. To repair an existing nvm install, run `npm install --include=optional` from the installed `@openai/codex` package directory | | `codex-update-manager status --json` shows `cli_status: "update_required"` for `/usr/bin/codex` on Arch | Pacman itself has a newer package for the installed CLI. Update through pacman instead of npm, for example `sudo pacman -Syu`; pacman-managed CLI installs are intentionally not auto-updated through npm | diff --git a/launcher/start.sh.template b/launcher/start.sh.template index 50995145a..f1c09d8b5 100644 --- a/launcher/start.sh.template +++ b/launcher/start.sh.template @@ -32,6 +32,21 @@ CODEX_LINUX_SETTINGS_FILE="$APP_SETTINGS_FILE" CODEX_LINUX_FEATURES_DIR="$SCRIPT_DIR/.codex-linux/features" export CODEX_HOME CODEX_LINUX_APP_ID CODEX_LINUX_APP_DISPLAY_NAME CODEX_LINUX_WEBVIEW_PORT CODEX_LINUX_SETTINGS_FILE CODEX_LINUX_FEATURES_DIR APP_STATE_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/$CODEX_LINUX_APP_ID" + +configure_runtime_tmpdir() { + [ -z "${TMPDIR:-}" ] || return 0 + + if [ -n "${XDG_RUNTIME_DIR:-}" ] && [ -d "$XDG_RUNTIME_DIR" ] && [ -w "$XDG_RUNTIME_DIR" ]; then + TMPDIR="$XDG_RUNTIME_DIR/$CODEX_LINUX_APP_ID/tmp" + else + TMPDIR="$APP_STATE_DIR/tmp" + fi + mkdir -p "$TMPDIR" + chmod 700 "$TMPDIR" + export TMPDIR +} + +configure_runtime_tmpdir APP_PID_FILE="$APP_STATE_DIR/app.pid" WEBVIEW_PID_FILE="$APP_STATE_DIR/webview.pid" LAUNCH_ACTION_RUNTIME_DIR="${XDG_RUNTIME_DIR:-$APP_STATE_DIR}/$CODEX_LINUX_APP_ID" diff --git a/tests/scripts_smoke.sh b/tests/scripts_smoke.sh index 6428443ec..89e17f04f 100755 --- a/tests/scripts_smoke.sh +++ b/tests/scripts_smoke.sh @@ -3121,6 +3121,48 @@ SCRIPT [ ! -s "$launcher_stderr" ] || fail "Expected launcher leading-zero canonicalization to be quiet, got: $(cat "$launcher_stderr")" } +test_launcher_uses_private_default_tmpdir() { + info "Checking launcher default TMPDIR isolation" + local workspace="$TMP_DIR/launcher-private-tmpdir" + local probe="$workspace/probe.sh" + local output="$workspace/output.log" + local runtime_dir="$workspace/runtime" + local state_dir="$workspace/state/codex-desktop" + local custom_tmp="$workspace/custom-tmp" + + mkdir -p "$runtime_dir" "$state_dir" "$custom_tmp" + cat > "$probe" <