Skip to content

Avoid predictable /tmp control socket fallback - #11

Open
minto-dane wants to merge 1 commit into
masterfrom
codex/fix-predictable-/tmp-control-socket-vulnerability
Open

Avoid predictable /tmp control socket fallback#11
minto-dane wants to merge 1 commit into
masterfrom
codex/fix-predictable-/tmp-control-socket-vulnerability

Conversation

@minto-dane

Copy link
Copy Markdown
Owner

Motivation

  • The previous control-socket fallback used a deterministic path under /tmp, allowing a local attacker to pre-create that pathname and prevent the bot from starting (local DoS).
  • The intent is to remove the predictable world-writable /tmp placement while preserving the ability to disambiguate instances by config fingerprint.

Description

  • Capture the user HOME and add FALLBACK_RUNTIME_DIR so the resolver prefers a per-user fallback at HOME/.cache/oo-bot/runtime-control when /run/oo-bot and XDG_RUNTIME_DIR are unavailable (preserves the config-hash socket name).
  • If HOME is not available, fall back to a config-scoped runtime dir adjacent to the config file at .oo-bot-runtime/<socket> instead of placing sockets directly under /tmp.
  • Keep the existing precedence order for OO_CONTROL_SOCKET_PATH, /run/oo-bot, and XDG_RUNTIME_DIR unchanged, and continue to use the config-derived hash suffix for uniqueness.
  • Update src/control.rs tests to cover the new home-based fallback and the config-scoped fallback.

Testing

  • Ran code formatting check with cargo fmt --check which passed without changes reported.
  • Attempted unit test run cargo test control::tests but the build was blocked by the lindera-ipadic crate build script failing to download dictionary assets in this environment, so tests could not complete.
  • Attempted cargo test --no-default-features control::tests which also failed for the same external lindera-ipadic asset-download issue, so test coverage could not be fully validated here.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8156b9d739

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/control.rs
}
}

config_path.parent().unwrap_or_else(|| Path::new(".")).join(".oo-bot-runtime").join(socket_name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the no-HOME fallback in a writable runtime location

When HOME and XDG_RUNTIME_DIR are unset and /run/oo-bot does not exist, this now puts the socket under the config file's parent. For deployments that point OO_CONFIG_PATH at /etc/oo-bot/oo-bot.yaml or another read-only config directory outside the packaged systemd unit, bind_runtime_control_listener will later fail its fs::create_dir_all(parent) call and the bot cannot start; the previous /tmp fallback still worked in that environment. Please choose a fallback that remains writable without requiring the config directory itself to be writable.

Useful? React with 👍 / 👎.

Comment thread src/control.rs
if let Some(path) = &context.home_dir {
let trimmed = path.trim();
if !trimmed.is_empty() {
return Path::new(trimmed).join(FALLBACK_RUNTIME_DIR).join(socket_name);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid overlong fallback Unix socket paths

When neither /run/oo-bot nor XDG_RUNTIME_DIR is available, adding the full $HOME/.cache/oo-bot/runtime-control/ prefix leaves only about 40 bytes for HOME before the pathname exceeds the Unix-domain socket sun_path limit on Linux. In long-home environments such as CI sandboxes, network-mounted homes, or nested workspaces, UnixListener::bind fails with AF_UNIX path too long, whereas the previous /tmp/oo-bot-control-<hash>.sock fallback stayed short. Please keep the fallback socket path bounded or shorten/hash the directory component.

Useful? React with 👍 / 👎.

Comment thread src/control.rs
}
}

config_path.parent().unwrap_or_else(|| Path::new(".")).join(".oo-bot-runtime").join(socket_name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve cwd-independent socket discovery without HOME

When HOME is unset and the config path is relative (the default is config/oo-bot.yaml), this fallback makes the socket directory relative to whichever cwd runs the command. If the bot is started from one directory and oo-bot control status/stop is invoked from another with the same relative OO_CONFIG_PATH, the client now looks in a different .oo-bot-runtime directory and cannot reach the running bot; the old /tmp/... fallback did not depend on cwd. Please make this fallback absolute or otherwise independent of the caller's working directory.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant