Skip to content

fix(exec-approvals): allow ~/.openclaw symlink when OPENCLAW_STATE_DIR is set#68417

Closed
acinader wants to merge 6 commits into
openclaw:mainfrom
acinader:fix/exec-approvals-state-dir-symlink
Closed

fix(exec-approvals): allow ~/.openclaw symlink when OPENCLAW_STATE_DIR is set#68417
acinader wants to merge 6 commits into
openclaw:mainfrom
acinader:fix/exec-approvals-state-dir-symlink

Conversation

@acinader

Copy link
Copy Markdown

What

Server deployments (e.g. the AWS CloudFormation template) place OpenClaw state at OPENCLAW_STATE_DIR=/data/openclaw and symlink ~/.openclaw → /data/openclaw for convenience. The exec approvals path check was tripping on this symlink with Refusing to traverse symlink in exec approvals path, blocking the AI from running any exec commands.

How

  • Added resolveApprovalsPathTrustedRoot(): when OPENCLAW_STATE_DIR is set, use fs.realpathSync(stateDir) as the trusted root instead of the HOME-relative walk
  • Updated ensureDir() to allow a symlinked approvals dir only when it resolves to exactly the configured state root (not any arbitrary directory)
  • Also validates that HOME itself contains no symlink components when OPENCLAW_STATE_DIR shifts the trusted root

Tests

Added two new cases to exec-approvals-store.test.ts:

  • Allows ~/.openclaw symlink when it resolves to exactly OPENCLAW_STATE_DIR
  • Rejects ~/.openclaw symlink when it resolves to a different directory

Notes

  • AI-assisted (Claude Sonnet 4.6 via OpenClaw) — reviewed with codex review --base origin/main, findings addressed
  • Fully tested: pnpm build && pnpm check && pnpm test pass

@greptile-apps

greptile-apps Bot commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a false-positive symlink rejection in ensureDir that was blocking exec commands on AWS server deployments where ~/.openclaw is intentionally symlinked to OPENCLAW_STATE_DIR. The fix introduces resolveApprovalsPathTrustedRoot() and updates ensureDir to allow the symlinked approvals directory only when it resolves to exactly the configured state root. Logic and test coverage look solid.

Confidence Score: 5/5

Safe to merge; one dead-code branch is the only finding.

All remaining findings are P2 style issues. The security-sensitive path logic is correct: symlinks are only permitted when OPENCLAW_STATE_DIR is explicitly set and the symlink resolves to exactly that root, and the test suite covers both the allow and reject cases.

No files require special attention.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/infra/exec-approvals.ts
Line: 265-268

Comment:
**Dead branch after `realpathSync`**

`fs.realpathSync` resolves all symlinks by definition, so `fs.lstatSync(realDir).isSymbolicLink()` can never return `true`. The `realStat.isSymbolicLink()` guard in the compound condition is unreachable dead code.

```suggestion
    const realStat = fs.lstatSync(realDir);
    if (!realStat.isDirectory()) {
      throw new Error(`Refusing to use unsafe exec approvals directory: ${dir}`);
    }
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(exec-approvals): allow ~/.openclaw s..." | Re-trigger Greptile

Comment thread src/infra/exec-approvals.ts

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

Copy link
Copy Markdown
Contributor

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: a7ab6fb764

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/infra/exec-approvals.ts
acinader and others added 3 commits April 17, 2026 22:41
@clawsweeper

clawsweeper Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Closing this as duplicate or superseded after Codex automated review.

Close this PR as duplicate/superseded. Current main still has the broader OPENCLAW_STATE_DIR exec-approvals gap, but this branch is no longer the best landing path: #72377 already merged the related symlinked-OPENCLAW_HOME cleanup, and open #62938 is the canonical remaining PR for making exec approvals respect OPENCLAW_STATE_DIR directly.

Best possible solution:

Close this PR as superseded, keep #62938 as the canonical implementation path for OPENCLAW_STATE_DIR exec-approvals storage, and fold any useful exact ~/.openclaw -> OPENCLAW_STATE_DIR regression coverage from this PR into that branch if maintainers still want it.

What I checked:

So I’m closing this here and keeping the remaining discussion on the canonical linked item.

Codex Review notes: model gpt-5.5, reasoning high; reviewed against 7d9dc8cf24fc.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant