Repository navigation
fix(media): require fs access for dynamic local roots - #55946
Conversation
Greptile SummaryThis PR narrows local-media-root widening so that Confidence Score: 5/5Safe 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.
|
| 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
There was a problem hiding this comment.
💡 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".
|
Addressed the bot feedback by narrowing root-expansion eligibility to non-workspace filesystem opt-ins, matching agent |
There was a problem hiding this comment.
💡 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".
3d8ae98 to
36f5af6
Compare
There was a problem hiding this comment.
💡 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".
sharkqwy
left a comment
There was a problem hiding this comment.
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.
|
Addressed the latest review feedback in
Added regressions for |
There was a problem hiding this comment.
💡 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".
|
Addressed the latest review item by confirming the call-path boundary.
Those callers pass only I re-ran the local gate while verifying this boundary:
|
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
Summary
getAgentScopedMediaLocalRootsForSources()widened local media roots from any absolute attachment path, even when the active tool profile did not expose filesystem reads.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
git blame, prior PR, issue, or refactor if known): Unknown.Regression Test Plan (if applicable)
src/media/local-roots.test.ts,src/agents/tool-fs-policy.test.tstools.fsopt-in still allows parent-root expansion.User-visible / Behavior Changes
Diagram (if applicable)
Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) NoYes/No) YesYes, explain risk + mitigation: local attachment access is narrowed for restrictive profiles by requiring effective filesystem-read access before widening parent roots.Repro + Verification
Environment
tools.profile: messaging; optionaltools.fs.workspaceOnly: falseSteps
pnpm test -- src/media/local-roots.test.ts src/agents/tool-fs-policy.test.ts.pnpm check./Users/peter/Pictureswithout filesystem opt-in, and does append it oncetools.fsis configured.Expected
Actual
Evidence
Attach at least one:
Human Verification (required)
pnpm check.Review Conversations
Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoRisks and Mitigations