Skip to content

fix(media): require fs access for dynamic local roots - #55946

Merged
jacobtomlinson merged 3 commits into
openclaw:mainfrom
jacobtomlinson:fix/telegram-read
Mar 27, 2026
Merged

jacobtomlinson merged 3 commits into
openclaw:mainfrom
jacobtomlinson:fix/telegram-read

Conversation

@jacobtomlinson

Copy link
Copy Markdown
Contributor

Summary

  • Problem: getAgentScopedMediaLocalRootsForSources() widened local media roots from any absolute attachment path, even when the active tool profile did not expose filesystem reads.
  • Why it matters: messaging-only agents could end up with broader local attachment access than their tool policy intended.
  • What changed: local media root expansion now checks the effective filesystem-read policy before appending source parent directories, while preserving existing behavior for profiles that explicitly allow filesystem tools.
  • What did NOT change (scope boundary): workspace-only handling, configured base media roots, and attachment normalization behavior outside this policy gate.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #
  • Related #
  • This PR fixes a bug or regression

Root Cause / Regression History (if applicable)

  • Root cause: media root synthesis trusted outbound attachment source paths without checking whether the current tool policy actually allowed local file reads.
  • Missing detection / guardrail: tests covered workspace-only gating, but not restrictive profiles that still route through outbound media helpers.
  • Prior context (git blame, prior PR, issue, or refactor if known): Unknown.
  • Why this regressed now: the helper synthesized extra parent roots to support local attachments, but did not align that behavior with restrictive profile resolution.
  • If unknown, what was ruled out: this was not caused by channel-specific adapters; the widening happened in the shared media root helper.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/media/local-roots.test.ts, src/agents/tool-fs-policy.test.ts
  • Scenario the test should lock in: messaging-profile agents keep their configured roots unless filesystem tools are explicitly enabled, while explicit tools.fs opt-in still allows parent-root expansion.
  • Why this is the smallest reliable guardrail: the behavior is decided in shared policy/root helpers before channel dispatch, so unit coverage on those helpers is the narrowest direct lock.
  • Existing test that already covers this (if any): the existing local-roots tests already covered workspace-only gating.
  • If no new test is added, why not:

User-visible / Behavior Changes

  • Messaging-profile agents no longer widen attachment roots from arbitrary local paths unless filesystem tools are explicitly enabled.

Diagram (if applicable)

Before:
[messaging-profile send with local media path] -> [append parent dir to allowed roots] -> [attachment path accepted]

After:
[messaging-profile send with local media path] -> [check effective fs-read access] -> [keep configured roots only]

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) Yes
  • If any Yes, explain risk + mitigation: local attachment access is narrowed for restrictive profiles by requiring effective filesystem-read access before widening parent roots.

Repro + Verification

Environment

  • OS: Ubuntu
  • Runtime/container: Node 24 / pnpm workspace
  • Model/provider: N/A
  • Integration/channel (if any): N/A
  • Relevant config (redacted): tools.profile: messaging; optional tools.fs.workspaceOnly: false

Steps

  1. Run pnpm test -- src/media/local-roots.test.ts src/agents/tool-fs-policy.test.ts.
  2. Run pnpm check.
  3. Confirm messaging-profile coverage does not append /Users/peter/Pictures without filesystem opt-in, and does append it once tools.fs is configured.

Expected

  • Restrictive profiles keep configured roots only.
  • Explicit filesystem opt-in preserves dynamic parent-root expansion.

Actual

  • Matches expected behavior with tests and local checks passing.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

  • Verified scenarios: targeted helper tests for messaging-profile gating and explicit filesystem opt-in, plus full pnpm check.
  • Edge cases checked: existing workspace-only behavior still short-circuits parent-root expansion.
  • What you did not verify: end-to-end delivery against a live channel.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps:

Risks and Mitigations

  • Risk: profiles that relied on implicit local attachment reads without explicit filesystem tool access will now reject those paths.
    • Mitigation: the prior behavior is preserved when filesystem tools are intentionally enabled, and the change is covered by direct helper tests.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Mar 27, 2026
@greptile-apps

greptile-apps Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR narrows local-media-root widening so that getAgentScopedMediaLocalRootsForSources no longer appends attachment parent directories for agents running under a restrictive tool profile (e.g. messaging) unless filesystem access is explicitly configured. The fix is well-scoped and correctly placed: a new resolveEffectiveToolFsReadEnabled policy helper checks whether the effective tool policy allows the "read" tool, and local-roots.ts gates appendLocalMediaParentRoots behind both the existing workspaceOnly check and the new read-enabled check.\n\nKey observations:\n\n- The resolveEffectiveToolFsReadEnabled implementation correctly resolves the merged profile/agent/alsoAllow policy before testing whether "read" is permitted, matching the semantics of isToolAllowedByPolicies elsewhere.\n- The new tests cover the three critical paths (open default, messaging-without-fs, messaging-with-fs) at both the policy-helper level and the local-roots integration level.\n- One subtle semantic gap: the agentTools?.fs || globalTools?.fs truthiness check treats any fs object — including fs: { workspaceOnly: true } — as an explicit opt-in that adds "read" to profileAlsoAllow. The function's correctness in that case depends entirely on the upstream resolveEffectiveToolFsWorkspaceOnly early-return in local-roots.ts; a future caller of resolveEffectiveToolFsReadEnabled in isolation could receive a misleading true for a workspace-restricted config.\n- Agent-scoped profile override (e.g. agent profile: \"coding\" under global profile: \"messaging\") is exercised by the logic but not covered by a test.

Confidence Score: 5/5

Safe to merge — the fix correctly narrows attachment-root widening for restrictive profiles and all findings are P2 quality concerns.

All remaining findings are P2: a potential semantic ambiguity in resolveEffectiveToolFsReadEnabled for workspaceOnly: true (safe in current callers due to the upstream guard) and missing agent-scoped override test coverage. No P0/P1 issues were found. The core logic is correct, tests lock in both the regression scenario and the explicit opt-in path.

src/agents/tool-fs-policy.ts — the fs truthiness opt-in check (lines 51–55) should be reviewed if resolveEffectiveToolFsReadEnabled is ever called outside of local-roots.ts.

Important Files Changed

Filename Overview
src/agents/tool-fs-policy.ts Adds resolveEffectiveToolFsReadEnabled — correctly gates on profile policy, alsoAllow, and sandbox policies. One subtle issue: the fs truthiness check treats workspaceOnly: true as an opt-in, safe only because the upstream caller guards with resolveEffectiveToolFsWorkspaceOnly first.
src/media/local-roots.ts Correctly adds the new resolveEffectiveToolFsReadEnabled guard after the existing workspaceOnly check, preserving correct evaluation order. Change is minimal and well-scoped.
src/agents/tool-fs-policy.test.ts Adds three tests covering the default/open, messaging-without-fs, and messaging-with-fs cases. Missing agent-scoped profile override scenarios.
src/media/local-roots.test.ts Adds two well-targeted integration tests matching the stated regression scenarios — messaging profile blocks widening, explicit tools.fs restores it. Both lock in the new behavior cleanly.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/tool-fs-policy.ts
Line: 51-55

Comment:
**Any `fs` object is treated as a filesystem opt-in, including `workspaceOnly: true`**

The truthiness check `agentTools?.fs || globalTools?.fs` adds `"read"` to `profileAlsoAllow` even when `fs` is configured as `{ workspaceOnly: true }`, which is semantically a *restriction* rather than an opt-in. The function returns `true` in that scenario, even though reads are actually workspace-scoped.

This is safe today only because `getAgentScopedMediaLocalRootsForSources` calls `resolveEffectiveToolFsWorkspaceOnly` first and returns early. But `resolveEffectiveToolFsReadEnabled` is a public export, and any future caller that relies on it in isolation — without the `workspaceOnly` guard — would receive a misleading `true` for a configuration like `{ profile: "messaging", fs: { workspaceOnly: true } }`.

Consider narrowing the opt-in check to exclude the pure workspace-restriction case, for example:

```typescript
// Only treat fs as an opt-in if it doesn't solely restrict to workspace
const fsIsOptIn = (agentTools?.fs && agentTools.fs.workspaceOnly !== true) ||
                  (globalTools?.fs && globalTools.fs.workspaceOnly !== true);
if (fsIsOptIn) {
  profileAlsoAllow.add("read");
  profileAlsoAllow.add("write");
  profileAlsoAllow.add("edit");
}
```

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

---

This is a comment left during a code review.
Path: src/agents/tool-fs-policy.test.ts
Line: 55-76

Comment:
**Missing coverage for agent-scoped profile override**

The new `resolveEffectiveToolFsReadEnabled` tests only exercise global `tools.profile`. There is no test for the case where an agent-specific profile overrides the global one, which is the most important override path since `agentTools?.profile ?? globalTools?.profile` gives agent config precedence.

For example, an agent with `profile: "coding"` under a global `profile: "messaging"` should return `true`, and an agent with `profile: "messaging"` under a global `profile: "coding"` should return `false`. These cases are worth pinning since the resolution logic is non-trivial and the fix depends on it behaving correctly in both directions.

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

Reviews (1): Last reviewed commit: "fix(media): require fs access for dynami..." | Re-trigger Greptile

Comment thread src/agents/tool-fs-policy.ts Resolved
Comment thread src/agents/tool-fs-policy.test.ts Resolved

@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: 76dda71ca4

ℹ️ 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/agents/tool-fs-policy.ts Resolved
@jacobtomlinson

Copy link
Copy Markdown
Contributor Author

Addressed the bot feedback by narrowing root-expansion eligibility to non-workspace filesystem opt-ins, matching agent alsoAllow precedence, and adding agent-override coverage in src/agents/tool-fs-policy.test.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: 3d8ae9882e

ℹ️ 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/agents/tool-fs-policy.ts Resolved

@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: 36f5af6d1e

ℹ️ 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/agents/tool-fs-policy.ts Resolved

@sharkqwy sharkqwy 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.

I think resolveEffectiveToolFsRootExpansionAllowed() still misses one override case. In src/agents/tool-fs-policy.ts, fsAllowsExpansion is computed as:

const fsAllowsExpansion =
  agentTools?.fs?.workspaceOnly === false || globalTools?.fs?.workspaceOnly === false;

That means a global tools.fs.workspaceOnly: false keeps root expansion enabled even when an agent explicitly tightens back down to tools.fs.workspaceOnly: true. We already treat agent-level tool config as the effective override in resolveToolFsConfig(), so this ends up widening media roots for an agent that tried to re-sandbox itself.

Suggested fix: derive this from the merged/effective FS config (or at least prefer the agent setting when it is present) before adding read/write/edit to profileAlsoAllow. A regression test with global workspaceOnly: false + agent workspaceOnly: true would catch it.

@jacobtomlinson

Copy link
Copy Markdown
Contributor Author

Addressed the latest review feedback in 66087f986e.

resolveEffectiveToolFsRootExpansionAllowed() now:

  • treats any explicit tools.fs block as an FS opt-in for restrictive profiles
  • derives workspaceOnly from the effective merged config, so agent-level tightening still wins over broader global settings

Added regressions for tools.fs: {} and for an agent overriding global workspaceOnly: false back to true.

@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: 66087f986e

ℹ️ 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/agents/tool-fs-policy.ts Resolved
@jacobtomlinson

Copy link
Copy Markdown
Contributor Author

Addressed the latest review item by confirming the call-path boundary.

resolveEffectiveToolFsRootExpansionAllowed() is only used from outbound local-media send paths:

  • src/infra/outbound/message-action-runner.ts
  • src/infra/outbound/deliver.ts
  • src/infra/outbound/outbound-send-service.ts

Those callers pass only cfg, agentId, and media-source hints; they do not have modelProvider or modelId available. So provider-scoped tool policy is not actionable in this pre-send root-expansion check, and threading provider policy into the helper here would be inventing context that the send pipeline does not currently have.

I re-ran the local gate while verifying this boundary:

  • pnpm test -- src/agents/tool-fs-policy.test.ts src/media/local-roots.test.ts
  • pnpm check

@jacobtomlinson
jacobtomlinson merged commit 824e16f into openclaw:main Mar 27, 2026
26 of 42 checks passed
@jacobtomlinson
jacobtomlinson deleted the fix/telegram-read branch March 27, 2026 19:06
johnkhagler pushed a commit to johnkhagler/openclaw that referenced this pull request Mar 29, 2026
* fix(media): require fs access for dynamic local roots

* fix(media): tighten fs root expansion policy

* fix(media): align fs root expansion with effective policy
alexcode-cc pushed a commit to alexcode-cc/clawdbot that referenced this pull request Mar 30, 2026
* fix(media): require fs access for dynamic local roots

* fix(media): tighten fs root expansion policy

* fix(media): align fs root expansion with effective policy
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
* fix(media): require fs access for dynamic local roots

* fix(media): tighten fs root expansion policy

* fix(media): align fs root expansion with effective policy
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
* fix(media): require fs access for dynamic local roots

* fix(media): tighten fs root expansion policy

* fix(media): align fs root expansion with effective policy
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* fix(media): require fs access for dynamic local roots

* fix(media): tighten fs root expansion policy

* fix(media): align fs root expansion with effective policy
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
* fix(media): require fs access for dynamic local roots

* fix(media): tighten fs root expansion policy

* fix(media): align fs root expansion with effective policy
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
* fix(media): require fs access for dynamic local roots

* fix(media): tighten fs root expansion policy

* fix(media): align fs root expansion with effective policy
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
* fix(media): require fs access for dynamic local roots

* fix(media): tighten fs root expansion policy

* fix(media): align fs root expansion with effective policy
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
* fix(media): require fs access for dynamic local roots

* fix(media): tighten fs root expansion policy

* fix(media): align fs root expansion with effective policy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants