fix: prevent sudo-caused file ownership corruption#59
Merged
Conversation
…er claude Running `sudo cac` could rewrite ~/.cac/ files as root, causing the claude wrapper to silently exit (set -e + unreadable root-owned JS files). - cmd_setup.sh: add warning when running as root; protect cp commands with `|| true` so init doesn't abort on existing root-owned files - templates.sh: use `-r` (readable) instead of `-f` (exists) when injecting fingerprint-hook.js and cac-dns-guard.js into NODE_OPTIONS/BUN_OPTIONS, so unreadable root-owned files are skipped gracefully instead of crashing
After 'sudo cac' runs, hook files (fingerprint-hook.js, relay.js, cac-dns-guard.js, blocked_hosts) become root-owned. On next normal-user run, cp/write fails silently (beta.2 fix), leaving old root-owned versions in place. Those files ARE readable (mode 644), so they get loaded via NODE_OPTIONS/BUN_OPTIONS but may be stale or corrupted. Fix: rm -f the target before writing. User owns ~/.cac/ directory so can always unlink files in it even if root-owned (rm needs write on parent dir, not on the file itself). This self-heals on next cac run. Version: 1.5.2-beta.3
Faking userID in .claude.json provided minimal protection (account_uuid still exposed via OAuth) but caused user_id mismatch errors after /login. Changes: - env create: no longer generates fake user_id or writes to .claude.json - env activate: remove _update_claude_json_user_id call - env check: auto-sync env/user_id from .claude.json (real value wins), never report mismatch error
- Bump version from 1.5.2-beta.3 to 1.5.2 - Update changelog (EN + ZH) with both fixes - Correct v1.5.0 user_id entry to reflect new behavior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Running
sudo cac <env>could corrupt~/.cac/file ownership:_ensure_initialized()runs as root, cp commands overwritefingerprint-hook.js/relay.jsas root-owned filesclaudeinvocations silently exit: the wrapper hasset -eand fails when bun/node tries to--preload/--requirean unreadable fileSymptoms:
cp: ~/.cac/fingerprint-hook.js: Permission deniedoncac <env>,claudesilently exits.Fix
cmd_setup.sh2>/dev/null || trueto bothcplines (was missing, unlike_write_dns_guard_jswhich already had|| true)templates.sh(wrapper)[[ -f ... ]]→[[ -r ... ]]forfingerprint-hook.js,cac-dns-guard.js,blocked_hosts-rchecks readability, not just existence — root-owned 600 files exist but can't be read, skipping injection is safe graceful degradation vs. silent crashTest