Skip to content

fix: block out-of-root reply media in restricted sessions - #160696

Closed
eleqtrizit wants to merge 4 commits into
openclaw:mainfrom
eleqtrizit:1068
Closed

eleqtrizit wants to merge 4 commits into
openclaw:mainfrom
eleqtrizit:1068

Conversation

@eleqtrizit

@eleqtrizit eleqtrizit commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Restricted channel sessions could still read and stage reply-media outside their canonical session root, reuse stale session authority when the current row disappeared, and finish an outbound copy after permission revocation. This change carries the existing session permission mode and root through every reply-media owner, constrains the final reader, and revalidates live authority immediately before managed staging. It composes with the session-permission, dynamic-root, and Gateway media protections already on the base branch.

What Problem This Solves

  1. Runner-owned normalization in src/auto-reply/reply/agent-runner-run.ts and src/auto-reply/reply/agent-runner-execution.ts created media contexts without the run's permissionMode or sessionRoot, so restricted modes fell back to broader config-level access.
  2. The final reader in src/auto-reply/reply/reply-media-paths.ts could inherit the broader agent workspace even when the session root was narrower.
  3. Delivery-stage normalization in src/auto-reply/reply/dispatch-from-config.prepare-delivery.ts could fall back to a captured session row when a current lookup returned no row.
  4. Live permission changes rebuilt the normalizer for later calls but did not fence a local-media load already awaiting I/O before its outbound save in src/media/outbound-attachment.ts.

The net effect was that model-authored local reply media could cross or outlive the active session filesystem boundary before being copied into managed outbound storage.

Why this design

  • Reuse the existing session permission mode and canonical session root instead of adding configuration or a second policy owner.
  • Enforce restricted-session containment at the final read capability, including when an underlying capability admits a broader workspace.
  • Fail closed when a previously present current session row cannot be read; never restore captured broader authority.
  • Intersect session-root confinement with the existing sender/group read capability; managed-only denial never becomes a new local-root grant.
  • Revalidate the exact current session authority after awaited loading and immediately before outbound persistence.
  • Preserve existing behavior for full and unset modes, and keep stricter config, tool-policy, sandbox, media-type, and media-size controls authoritative.

Why this does not conflict with related PRs

PR Governed layer Relation to this PR
#124909 Session permission modes and canonical session roots Supplies the existing authority this change carries into reply-media normalization.
#55946 Tool-policy checks for dynamic local media roots Remains the effective config/tool-policy gate; this change adds the missing session-scoped final-reader restriction.
#152079 Gateway-owned WebChat media normalization Its Gateway enforcement remains unchanged; this change aligns runner-owned and delivery-stage sibling paths with that boundary.

The branch's merge base already contains the shipped behavior from these changes. Shared reply-media files are touched only to compose the existing owners and add current-authority invalidation at the staging sink.

Evidence

Path and mode Final effect Exact-head result
Runner, restricted session with session root nested inside agent workspace In-root bytes staged; nearest file inside the broader workspace but outside the session root rejected 8-case real owner matrix passed
Runner, restricted session with sender-scoped deny: ["read"] In-root and outside-root files both rejected; zero bytes staged 8-case real owner matrix passed
Runner, full and unset modes Both authorized files staged 8-case real owner matrix passed
Runner, full with stricter config In-agent-workspace file staged; outside-agent-workspace file rejected 8-case real owner matrix passed
Runner, live full → workspace change during an awaited media load Commit guard rejected the stale preparation before outbound persistence Deterministic revocation regression passed
Delivery stage after current session row disappears Host-local media denied instead of using captured full authority Routed delivery regression passed
Delivery stage when a session row is created after dispatch, then revoked during awaited loading Current row identity and revision revalidated; final persistence denied and a delivery-failure receipt emitted Real normalizer and outbound staging regression passed
Sandboxed and managed media paths Existing sandbox rejection and independently managed-media behavior preserved Existing reply-media suite passed
Focused behavior Outbound staging, normalization, runner ownership, and routed dispatch 187 tests passed on exact head 8aa29525f61
Static and changed-file gates Production types, 26 core test type graphs, lint, format, dead-code, import-cycle, schema, and boundary guards pnpm tsgo and pnpm run check:changed --base upstream/main passed; branch autoreview found no P0/P1/P2 defects at 0.95 confidence

The sink-level observations are the staged-media counts, rejected outside-root read, missing-row denial, failure receipt, and commit guard firing before saveMediaBuffer can persist bytes.

SDK / caller upgrade contract

  • full and unset sessions retain their existing attachment behavior.
  • Config-only workspaceOnly sessions retain access within the configured agent workspace.
  • Restricted sessions retain in-root and independently managed media access; local paths outside the recorded session root now fail closed with the existing delivery-failure receipt.
  • Operators can move or regenerate an attachment inside the canonical session root before replying.
  • The distinct-root runner matrix, missing-row delivery regression, and creation-then-revocation final-effect regression cover this contract.

Testing

  • Added final-effect coverage to src/auto-reply/reply/agent-runner.media-ownership.test.ts, src/auto-reply/reply/reply-media-paths.test.ts, src/auto-reply/reply/dispatch-from-config.media-ownership.test-utils.ts, and src/media/outbound-attachment.test.ts.
  • Passed 187 focused tests across the four affected suites on exact head 8aa29525f61; the dispatch suite passed 138/138 and the creation-then-revocation case used the real media normalizer and outbound staging sink.
  • Passed pnpm tsgo.
  • Passed pnpm run check:changed --base upstream/main with all 26 core test type graphs and an EXIT=0 result.
  • Passed branch autoreview with no accepted P0/P1/P2 findings and overall correctness confidence 0.95.
  • No tracking-ticket, advisory, private-worklog, or release-note references are included in this public description.

@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Sep 28, 2026
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 29, 2026, 12:09 AM ET / 04:09 UTC (Revision 5).

ClawSweeper review

What this changes

The branch carries session permissions into agent reply-media handling, confines restricted local reads to the session root, adds an outbound staging guard, and extends boundary tests.

Merge readiness

⛔ Blocked before merge - 8 items remain

Current main still lacks the reported boundary. The latest commit addresses the prior finding for a session row created before normalization, but a row created afterward can still escape the final staging check. The upgrade behavior also needs an owner decision.

Priority: P0
Reviewed head: 8aa29525f61500c4fda3f3efdd23362a93237d67
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The branch has substantial boundary coverage, but the remaining final-effect window and incomplete authority proof limit merge confidence.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: Authority-chain proof required: The branch's runner matrix exercises actual local files and the production media sink, and its routed test uses the real normalizer with injected session state. It does not show that a row created after an absent-row lookup, or a replaced generation with matching policy fields, is rejected before final filesystem publication; the routed assertion checks the failure receipt but not staged-file absence. A redacted production-path final-effect trace would close this gap; update the PR body to trigger re-review, or ask a maintainer for @clawsweeper re-review if it does not. Redact private paths, endpoints, and credentials. No stored-data contract changes.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: Authority-chain proof required: The branch's runner matrix exercises actual local files and the production media sink, and its routed test uses the real normalizer with injected session state. It does not show that a row created after an absent-row lookup, or a replaced generation with matching policy fields, is rejected before final filesystem publication; the routed assertion checks the failure receipt but not staged-file absence. A redacted production-path final-effect trace would close this gap; update the PR body to trigger re-review, or ask a maintainer for @clawsweeper re-review if it does not. Redact private paths, endpoints, and credentials. No stored-data contract changes.
Evidence reviewed 10 items Current-main necessity: Current main creates the reply-media context without the branch's session-mode propagation or final staging guard.
Documented boundary: Restricted session modes confine file reads to the recorded session root, falling back to the agent workspace only when no root was recorded.
Remaining authority gap: The delivery normalizer snapshots a possibly absent row and installs a commit assertion only when that snapshot contains a row. Its later comparison also omits sessionId and lifecycleRevision.
Findings 2 actionable findings [P1] Fence staging when a session row appears after the lookup
[P2] Move added session reads off the Gateway thread
Security Needs attention New session authority can bypass the staging fence: A restricted row created after the lookup is not represented by a commit assertion, so publication can proceed under the earlier broader read context. The guard also omits session-generation identity from its present-row comparison.

How this fits together

Agent replies can contain local file paths. Reply-media handling checks the session and sender's read permissions, copies permitted files into managed outbound storage, and passes the result or a failure receipt to channel delivery.

flowchart LR
A[Agent reply with media path] --> B[Current session permissions]
B --> C[Sender read policy]
C --> D[Local file reader]
D --> E{Read permitted?}
E -->|Yes| F[Outbound staging]
E -->|No| G[Delivery failure receipt]
F --> H[Channel reply]
Loading

Decision needed

Question Recommendation
Should upgraded restricted sessions reject out-of-root local reply attachments with a visible failure receipt and guidance to move or regenerate the file inside the session root? Enforce the recorded root: Accept the documented restriction once the final staging fence and operator recovery guidance are complete.

Why: The documented boundary supports rejection, but it deliberately changes attachment delivery for existing operators; the PR author’s description does not itself accept that tradeoff for the product.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: Authority-chain proof required: The branch's runner matrix exercises actual local files and the production media sink, and its routed test uses the real normalizer with injected session state. It does not show that a row created after an absent-row lookup, or a replaced generation with matching policy fields, is rejected before final filesystem publication; the routed assertion checks the failure receipt but not staged-file absence. A redacted production-path final-effect trace would close this gap; update the PR body to trigger re-review, or ask a maintainer for @clawsweeper re-review if it does not. Redact private paths, endpoints, and credentials. No stored-data contract changes.
  • Fence staging when a session row appears after the lookup (P1) - When this lookup returns no row, assertCommitAllowed is omitted. A row can be created with restricted permissions while local media loading awaits I/O, and the broader preparation can then publish without a final session check. Install a final check for the no-row state too, and bind present rows to sessionId and lifecycle revision as well as permission fields.
  • Move added session reads off the Gateway thread (P2) - The new per-payload lookup and staging assertion call resolveSessionStoreLookup, which reaches the synchronous SQLite session reader during Gateway delivery. This extends a legacy main-thread database path on every staged attachment. Use the session-store read worker for preparation and an owner-published generation fact for the synchronous final-effect check.
  • Resolve security concern: New session authority can bypass the staging fence - A restricted row created after the lookup is not represented by a commit assertion, so publication can proceed under the earlier broader read context. The guard also omits session-generation identity from its present-row comparison.
  • Resolve merge risk (P1) - A session row created after delivery observes no row can acquire restricted authority while an attachment is loading, yet the conditional commit guard allows the old broad preparation to publish.
  • Resolve merge risk (P1) - Existing restricted sessions that previously attached files outside their recorded root will now receive delivery failures; the operator-facing upgrade outcome needs explicit owner acceptance.
  • Complete next step (P2) - Repair the absent-row and generation staging fence, move the new session reads off the Gateway thread, provide redacted final-effect proof, and obtain owner acceptance of the restricted-session upgrade behavior.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P1] Fence staging when a session row appears after the lookup — src/auto-reply/reply/dispatch-from-config.prepare-delivery.ts:149-161
  • [P2] Move added session reads off the Gateway thread — src/auto-reply/reply/dispatch-from-config.prepare-delivery.ts:121
  • [high] New session authority can bypass the staging fence — src/auto-reply/reply/dispatch-from-config.prepare-delivery.ts:149
Agent review details

Security

Needs attention: The new final-effect guard still has a reachable no-row authority window before outbound publication.

PR surface

Source +132, Tests +382. Total +514 across 19 files.

View PR surface stats
Area Files Added Removed Net
Source 10 149 17 +132
Tests 9 406 24 +382
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 19 555 41 +514

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Finish the final authority fence (recommended)
    Bind no-row and present-row preparations to the live session generation and prove rejection before outbound publication.
  2. Pause the boundary change
    Hold the PR if its final publication check and restricted-session upgrade outcome cannot be made explicit.

Technical review

Best possible solution:

Use a session-store-owned generation fact at final publication, preserve the intersection of session-root and sender-read permissions, and give operators an actionable attachment failure.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: use a restricted session whose root is nested within the agent workspace and reply with a local path in the workspace but outside that root. Current main prepares that path without the branch’s session-root reader; this read-only review did not execute the flow.

Is this the best way to solve the issue?

No, not yet. Reusing the existing session and read-policy owners is the right direction, but the final guard must cover a newly appearing row and session-generation changes without adding synchronous database reads to delivery.

Full review comments:

  • [P1] Fence staging when a session row appears after the lookup — src/auto-reply/reply/dispatch-from-config.prepare-delivery.ts:149-161
    When this lookup returns no row, assertCommitAllowed is omitted. A row can be created with restricted permissions while local media loading awaits I/O, and the broader preparation can then publish without a final session check. Install a final check for the no-row state too, and bind present rows to sessionId and lifecycle revision as well as permission fields.
    Confidence: 0.91
  • [P2] Move added session reads off the Gateway thread — src/auto-reply/reply/dispatch-from-config.prepare-delivery.ts:121
    The new per-payload lookup and staging assertion call resolveSessionStoreLookup, which reaches the synchronous SQLite session reader during Gateway delivery. This extends a legacy main-thread database path on every staged attachment. Use the session-store read worker for preparation and an owner-published generation fact for the synchronous final-effect check.
    Confidence: 0.86

Overall correctness: patch is incorrect
Overall confidence: 0.89

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5902fd290c4c.

Labels

Label changes:

No label changes.

Label justifications:

  • P0: The item concerns a local-file security boundary that can expose files through outbound attachment staging.
  • merge-risk: 🚨 compatibility: Restricted sessions that previously delivered out-of-root attachments will now fail those attachments.
  • merge-risk: 🚨 security-boundary: The conditional final staging guard still permits a plausible stale-authority publication window.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Authority-chain proof required: The branch's runner matrix exercises actual local files and the production media sink, and its routed test uses the real normalizer with injected session state. It does not show that a row created after an absent-row lookup, or a replaced generation with matching policy fields, is rejected before final filesystem publication; the routed assertion checks the failure receipt but not staged-file absence. A redacted production-path final-effect trace would close this gap; update the PR body to trigger re-review, or ask a maintainer for @clawsweeper re-review if it does not. Redact private paths, endpoints, and credentials. No stored-data contract changes.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. Restricted-session attachment delivery and its visible failure receipt can be observed in a Telegram Test Server chat.

Evidence

Security concerns:

  • [high] New session authority can bypass the staging fence — src/auto-reply/reply/dispatch-from-config.prepare-delivery.ts:149
    A restricted row created after the lookup is not represented by a commit assertion, so publication can proceed under the earlier broader read context. The guard also omits session-generation identity from its present-row comparison.
    Confidence: 0.9

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • eleqtrizit: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • jacobtomlinson: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Fence both absent and present session snapshots at publication, including session identity and lifecycle revision.
  • Use worker-prepared session facts and an owner-published generation check instead of new synchronous Gateway database reads.
  • Add redacted final-effect evidence showing allowed staging and nearest forbidden or revoked staging with no published file.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-28T20:36:31.585Z sha a8208b3 :: needs real behavior proof before merge. :: [P1] Constrain reads to the session root | [P1] Fail closed when the current session row is unavailable | [P1] Fence media loads already running during revocation
  • reviewed 2026-09-29T00:10:03.830Z sha a8208b3 :: needs real behavior proof before merge. :: [P1] Constrain reads to the session root | [P1] Fail closed when the current session row is unavailable | [P1] Fence media loads already running during revocation
  • reviewed 2026-09-29T01:17:18.856Z sha 3f98110 :: needs real behavior proof before merge. :: [P1] Preserve denied file reads when narrowing to the session root
  • reviewed 2026-09-29T02:17:28.063Z sha d5556bc :: needs real behavior proof before merge. :: [P1] Fence staging against sessions created after dispatch starts

@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@eleqtrizit

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Sep 29, 2026
@eleqtrizit
eleqtrizit marked this pull request as ready for review September 29, 2026 03:57
@eleqtrizit

Copy link
Copy Markdown
Contributor Author

Closing without merge after a precedent review. #152079 intentionally preserved external-channel staging while applying session-root restrictions to Gateway-owned media, including regression coverage that allows outside-root staging for non-Gateway channels. This change would therefore redefine shipped product policy rather than fix an established security boundary. Any universal session-root restriction should be proposed separately with explicit compatibility and design review.

@eleqtrizit eleqtrizit closed this Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant