Skip to content

fix(cli): prevent symlink attacks during instruction writes - #145

Closed
tachyon-beep wants to merge 1 commit into
mainfrom
codex/propose-fix-for-symlink-vulnerability
Closed

fix(cli): prevent symlink attacks during instruction writes#145
tachyon-beep wants to merge 1 commit into
mainfrom
codex/propose-fix-for-symlink-vulnerability

Conversation

@tachyon-beep

Copy link
Copy Markdown
Collaborator

Motivation

  • The instruction installer used a predictable PID-based sibling temp path and fs::write, which could follow a pre-planted symlink and allow attacker-influenced arbitrary overwrites during atomic_write.
  • The change hardens the atomic-write path to avoid following attacker-controlled symlinks while preserving existing behaviour like same-filesystem atomic rename and permission preservation.

Description

  • Replace the deterministic temp-path + fs::write pattern with tempfile::Builder::tempfile_in(parent) and an exclusive NamedTempFile, then write_all and persist to atomically install the file in the target directory.
  • Preserve the existing guards: refuse empty payloads and retain permission copying via preserve_mode, and keep the write/rename as a same-filesystem atomic operation.
  • Promote tempfile to a runtime dependency and add use std::io::Write; for write_all.
  • Add a regression test atomic_write_does_not_follow_predictable_temp_symlink that plants the legacy predictable temp symlink and verifies the victim is not overwritten while the intended target is updated.

Testing

  • Ran cargo fmt --check, which succeeded.
  • Ran cargo test -p loomweave-cli instructions::tests::atomic_write, and the targeted tests passed (atomic_write_refuses_empty_content, atomic_write_preserves_mode, atomic_write_does_not_follow_predictable_temp_symlink).
  • Ran cargo clippy -p loomweave-cli --all-targets -- -D warnings, which completed without warnings.
  • Verified repository state with git diff --check and git status --short after committing the fix.

Codex Task

Copilot AI lite review requested due to automatic review settings September 1, 2026 18:49
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Copilot AI 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.

Pull request overview

This PR hardens loomweave-cli’s instruction installer against symlink-based arbitrary overwrite attacks by replacing a predictable, PID-based temp file write with a securely-created temporary file that cannot be pre-symlinked by an attacker, while keeping the same-directory atomic rename behavior and permission preservation.

Changes:

  • Replace deterministic sibling temp-path + fs::write with tempfile::NamedTempFile created via tempfile_in(parent), followed by write_all and persist.
  • Preserve Unix permission-copy behavior via preserve_mode before the final atomic persist/rename.
  • Add a Unix regression test that plants the legacy predictable temp-path symlink and asserts the “victim” file is not overwritten.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/loomweave-cli/src/instructions.rs Uses NamedTempFile for safe atomic writes and adds a regression test for the predictable-temp symlink attack.
crates/loomweave-cli/Cargo.toml Promotes tempfile to a runtime dependency to support the hardened write path.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@tachyon-beep

Copy link
Copy Markdown
Collaborator Author

Superseded by the rebase onto release/1.6.0, which also widens the fix to the other five staging sites of the same class and keeps umask-derived file modes.

@tachyon-beep
tachyon-beep deleted the codex/propose-fix-for-symlink-vulnerability branch September 1, 2026 20:04
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.

2 participants