Skip to content

fix(asset): close staging symlink/TOCTOU bypass, log swallowed blob-reclaim errors - #357

Merged
getappz merged 2 commits into
masterfrom
task/179
Jul 28, 2026
Merged

fix(asset): close staging symlink/TOCTOU bypass, log swallowed blob-reclaim errors#357
getappz merged 2 commits into
masterfrom
task/179

Conversation

@getappz

@getappz getappz commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • asset attach now rejects symlinked staging files and reads size+content from one O_NOFOLLOW-opened handle (Unix) instead of separate exists/stat/read calls, closing a symlink/TOCTOU bypass at the staging path.
  • delete_disk_blob (agentflare-store) now logs unlink failures (except NotFound) instead of silently discarding them via let _ = — the DB row is already gone by that point, so a failed unlink previously left an orphaned file with no way to be rediscovered or retried.

Closes agentflare item #179 (CodeRabbit findings on PR #253's asset.rs, re-audited — finding 2's actual code had since moved from asset.rs into agentflare-store's doc_delete/blob_unref; the delete-ordering logic there was already correct, the swallowed-error gap was specifically in delete_disk_blob).

Test plan

  • cargo test -p agentflare -p agentflare-store — 110 tests pass, including new asset_attach_rejects_symlink (Unix-only)
  • cargo clippy -p agentflare -p agentflare-store --all-targets --all-features -- -D warnings -A unsafe_code -A clippy::pedantic — clean
  • cargo fmt --check — clean

Summary by CodeRabbit

  • Bug Fixes
    • Improved cleanup error reporting when stored files cannot be removed.
    • Strengthened asset attachment validation to reject symbolic links and prevent unsafe file access.
    • Improved handling and reporting of missing, unreadable, or oversized staged files.
  • Tests
    • Added coverage confirming that symbolic links cannot be attached as assets.

…eclaim errors

asset attach now rejects symlinked staging files and reads size+content
from one no-follow-opened handle instead of separate exists/stat/read
calls. delete_disk_blob logs unlink failures (except NotFound) instead
of discarding them silently, since the DB row is already gone and the
orphaned file otherwise has no way to be rediscovered.

Closes item #179.
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@getappz, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 8 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3a4b15ee-9f55-422b-83ec-f87933d123bb

📥 Commits

Reviewing files that changed from the base of the PR and between 1b916b3 and 5f55cc9.

📒 Files selected for processing (3)
  • crates/agentflare-store/src/blobs.rs
  • src/mcp_server/asset.rs
  • src/mcp_server/tests/asset_tests.rs
📝 Walkthrough

Walkthrough

MCP asset attachment now rejects staged symlinks, uses hardened bounded reads, and includes Unix coverage for symlink rejection. Disk blob deletion now logs unexpected file removal errors while ignoring missing files.

Changes

Asset attachment hardening

Layer / File(s) Summary
Hardened staged-file attachment
src/mcp_server/asset.rs, src/mcp_server/tests/asset_tests.rs
The attach flow rejects symlinked staging paths, opens files with Unix O_NOFOLLOW, reads at most max_attach + 1 bytes, and tests symlink rejection.

Blob cleanup reporting

Layer / File(s) Summary
Reported blob removal errors
crates/agentflare-store/src/blobs.rs
Disk blob deletion ignores NotFound and logs other file-removal errors.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the symlink/TOCTOU hardening and blob cleanup logging changes.
Description check ✅ Passed The description includes a clear summary and a concrete test plan; only the reviewer notes section is missing.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task/179

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/agentflare-store/src/blobs.rs`:
- Around line 78-81: Update the comment above delete_disk_blob to state that the
row is already gone or was never inserted, covering both the blob_unref and
blob_store call paths while preserving the existing retry and logging rationale.

In `@src/mcp_server/asset.rs`:
- Around line 46-80: Update the symlink_metadata match in the asset attachment
flow to allow only regular files: keep the existing symlink-specific error,
reject every other non-regular file type—including directories, FIFOs, devices,
and sockets—with an invalid-params error, and retain the existing missing-file
handling. Use the metadata file-type check before OpenOptions::open in the
surrounding attach method.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5de26073-9b90-46ee-b55b-d4f732eaf8fb

📥 Commits

Reviewing files that changed from the base of the PR and between 952b09d and 1b916b3.

📒 Files selected for processing (3)
  • crates/agentflare-store/src/blobs.rs
  • src/mcp_server/asset.rs
  • src/mcp_server/tests/asset_tests.rs

Comment thread crates/agentflare-store/src/blobs.rs Outdated
Comment thread src/mcp_server/asset.rs
… comment

FIFOs/devices/sockets shared symlink-metadata's fall-through Ok(_) => {}
branch, so a named pipe dropped into staging would hang the attach
thread on the blocking read once opened. Reject anything that isn't a
regular file, same as the symlink check.

Also corrects delete_disk_blob's comment: it's called from blob_store's
insert-failure cleanup too, where no row was ever inserted, not just
from blob_unref where one existed and is now gone.
@getappz

getappz commented Jul 28, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@getappz
getappz merged commit 7cbff1b into master Jul 28, 2026
15 checks passed
@getappz
getappz deleted the task/179 branch July 28, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant