Skip to content

fix(api): keep object-storage tools out of the org filesystem - #7883

Closed
vibegui wants to merge 1 commit into
mainfrom
fix/org-fs-manifest-bypass
Closed

vibegui wants to merge 1 commit into
mainfrom
fix/org-fs-manifest-bypass

Conversation

@vibegui

@vibegui vibegui commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What is this contribution about?

An agent that wrote a file to the Library with PUT_PRESIGNED_URL (key _fs/home/pages/x.html) got the bytes into the bucket but never saw the file in the Library. The Library lists from the org_fs_entry Postgres index, which only the /api/:org/fs routes (OrgFs.write()) maintain, so a raw write is invisible. A raw DELETE_OBJECT on an _fs/ key does the reverse: it leaves an index row with no bytes.

  • PUT_PRESIGNED_URL, DELETE_OBJECT and DELETE_OBJECTS now reject keys in the _fs/ namespace, with an error that points to PUT/DELETE /api/<org>/fs/<volume>/file (decocms api). The check normalizes the key like buildS3Key (isOrgFsKey in org-fs-path.ts), so a/../_fs/x, a leading slash, backslashes and percent-encoded spellings are caught too.
  • Tool descriptions say so, so agents see it before calling.
  • The decocms-studio skill contradicted itself: rest.md said "write files through fs, not object-storage" and then "Prefer the tools (PUT_PRESIGNED_URL, DELETE_OBJECT)". Both docs now send org files to the fs routes and keep the tools for non-_fs/ keys.

No new CLI command: decocms api (after decocms auth login) already reaches the fs routes with the user's session.

How did you verify your code works?

  • New tests: isOrgFsKey (spellings that must match and keys that must not, e.g. chat-uploads/_fs/a, _fsx/a), PUT_PRESIGNED_URL and DELETE_OBJECT(S) rejecting _fs/ keys without touching storage, and DELETE_OBJECT still deleting an ordinary key. bun test src/tools/object-storage src/file-storage/org-fs-path.test.ts: 20 pass, 0 fail.
  • bun run fmt, bun run lint, bun run knip and apps/api tsc --noEmit are clean.
  • bun test src/tools src/file-storage fails 97 tests with and without this change (base: 1123 pass / 97 fail; this branch: 1129 pass / 97 fail). They are the Postgres-backed integration suites and my machine has no local Postgres role. CI covers them.
  • Confirmed the root cause against prod: no org_fs_entry row existed for a file uploaded through the presigned URL, while neighbouring files written through fs had rows.
  • Not run: the E2E suite, and a live decocms api write against prod from this branch.

How to Test

  1. Call PUT_PRESIGNED_URL with {"key":"_fs/home/test.html"}. Expected: error naming the org filesystem and the fs route.
  2. Call it with {"key":"uploads/test.txt"}. Expected: a URL, as before.
  3. decocms api "/api/<slug>/fs/home/file?path=test.html" -X PUT -H "Content-Type: text/html" -d @test.html. Expected: {entry} and the file shows up in the Library.

Migration Notes

None. Existing orphaned objects under _fs/ (written before this change) stay invisible; they can be re-uploaded through the fs route.

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working
  • Documentation is updated (skill docs)
  • No breaking changes (tools still work for every non-_fs/ key)

🤖 Generated with Claude Code


Summary by cubic

Causes object-storage tools to reject _fs/ keys so org files always go through the filesystem routes that maintain the Library index.

  • Old behavior: PUT_PRESIGNED_URL wrote bytes to _fs/... without creating a Library entry, and DELETE_OBJECT(S) could remove bytes while leaving a stale index row.
  • The new guard normalizes keys like buildS3Key, catching a/../_fs/x, leading slashes, backslashes, and percent-encoded spellings.
  • Tool descriptions and the decocms-studio skill now direct org files to PUT/DELETE /api/<org>/fs/<volume>/file.

Written for commit 44e49f3. Summary will update on new commits.

View guided diff Turn on auto-fix

PUT_PRESIGNED_URL, DELETE_OBJECT and DELETE_OBJECTS accept any key, including
`_fs/<volume>/...`, where org filesystem bytes live. The Library lists files
from the `org_fs_entry` index, which only the /api/:org/fs routes write, so an
agent that uploads to `_fs/home/pages/x.html` through a presigned URL gets
bytes in the bucket and nothing in the Library; a raw delete leaves an index
row with no bytes behind.

Reject `_fs/` keys in those three tools (normalized like buildS3Key, so
`a/../_fs/x` and encoded spellings count) and point to the fs route. Fix the
decocms-studio skill, whose rest.md told agents to prefer those tools while
the line above it said to write files through `fs`.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@viktormarinho

Copy link
Copy Markdown
Contributor

Closing in favor of #7885, which includes this commit and builds on it: instead of rejecting _fs/ keys, PUT_PRESIGNED_URL now returns a Studio upload URL (signed one-file grant) that writes through OrgFs, and DELETE_OBJECT(S) delete through OrgFs, so the Library index stays in step either way. Thanks for tracking down the root cause.

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

Labels

claude PR authored by a coding agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants