#7007: Fix security audit false-positive for symlinked state dir
agents
Cluster:
Session File Path Management
### Problem
OpenClaw's legacy state-dir migration intentionally creates a symlink like ~/.clawdbot -> ~/.openclaw. On POSIX, symlink mode bits are not meaningful, but the security audit was using lstat() and treating the symlink's 777 bits as world-writable, producing a critical false-positive.
### Fix
- Keep reporting the state dir as a symlink (trust boundary warning).
- Evaluate read/write bits on the symlink target via stat() (follows symlink) on non-Windows platforms.
### Tests
- Added a POSIX test that creates a state dir symlink to a 0700 dir and asserts we warn about symlink but do not flag world-writable.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Updates the filesystem permission audit to treat POSIX symlink mode bits as non-authoritative: it still flags the state directory as a symlink (trust-boundary warning), but derives read/write bits from the symlink target via `stat()` (following the link) on non-Windows platforms. Adds a regression test ensuring a symlinked state dir pointing to a `0700` directory triggers the symlink warning without incorrectly flagging world-writable perms.
This fits into the existing `src/security` audit framework by refining `inspectPathPermissions()` to report more accurate POSIX permission findings while preserving the existing Windows ACL-based checks.
<h3>Confidence Score: 4/5</h3>
- This PR is generally safe to merge and fixes a real false-positive, with minor consistency/cleanup issues to consider.
- The change is localized and aligns with POSIX semantics for symlink mode bits, and the added test covers the reported regression. Remaining concerns are minor: an internal inconsistency in `inspectPathPermissions()` on the Windows codepath (bits computed outside the branch) and test temp-dir cleanup.
- src/security/audit-fs.ts (Windows branch consistency); src/security/audit.test.ts (temp dir cleanup).
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#9154: fix(doctor): resolve symlinks before comparing state directories
by gavinbmoore · 2026-02-04
79.3%
#16957: fix(doctor): skip false positive permission warnings for Nix store ...
by soumikbhatta · 2026-02-15
78.1%
#6257: Fix: Create sensitive directories with mode 0o700
by sloppy-claw · 2026-02-01
78.1%
#18593: fix: resolve symlinks in session path validation (#18553)
by EpaL · 2026-02-16
78.0%
#11408: Security: resolve symlink target permissions in safeStat; skip doct...
by lailoo · 2026-02-07
77.0%
#22910: fix(browser): resolve symlinks in upload path validation
by erdinccurebal · 2026-02-21
76.8%
#23308: fix(browser): accept upload paths that traverse symlinked tmp dirs
by SidQin-cyber · 2026-02-22
76.6%
#11439: fix(security): warn on relative OPENCLAW_CONFIG_PATH and disable co...
by coygeek · 2026-02-07
75.8%
#20823: fix(security): Windows ACL audit false-positive with localized SYST...
by xinhuagu · 2026-02-19
75.6%
#16929: fix(security): block access to sensitive directories from within sa...
by CornBrother0x · 2026-02-15
75.6%