Skip to content

fix(v6.50.2): batch endpoints enforce collection write-scope per item (ADR-250) - #302

Merged
cgbarlow merged 1 commit into
mainfrom
fix/batch-write-scope
Sep 24, 2026
Merged

cgbarlow merged 1 commit into
mainfrom
fix/batch-write-scope

Conversation

@cgbarlow

Copy link
Copy Markdown
Owner

Problem

A user restricted to certain collections (ADR-237) can still write to any collection through the batch endpoints, which MCP agents and the CLI use. None of the ten /api/batch/{elements,diagrams}/{delete,clone,set,tags} and /api/batch/elements/{create,update} endpoints checked write-scope; only the ADR-249 relationship batch did. The single-item endpoints refuse the same writes with 403. I reproduced it with a scoped architect: every one of the ten endpoints wrote into a collection outside their scope. The #298 agent first spotted this and recorded it in ADR-249.

Fix

  • Every batch operation now checks each item against the user's scope, using the same rule as the matching single-item endpoint:
    • delete, tags, update, clone: the item's own collection. A clone lands beside its original.
    • set (move to another set): both the collection the item leaves and the one it joins.
    • element create: the effective set's collection, as POST /api/elements does (ADR-238).
  • Out-of-scope items fail on their own with Outside your collection write-scope and are left untouched. The rest of the batch still runs.
  • One helper, _require_writable, is shared by all eleven batch operations. The relationship batch now uses it too instead of its own inline copy.
  • Unrestricted users and admins see no change. No schema, endpoint, MCP tool or CLI change.

Tests

  • New backend/tests/test_authz/test_batch_write_scope.py, written first:
    • Each of the 11 scoped cases (element and diagram delete, clone, tags and both move directions; element create and update) sends one in-scope and one out-of-scope item. It checks that exactly the out-of-scope item fails and is left unchanged.
    • All 11 failed before the fix and pass after.
    • Two more tests confirm unrestricted users and admins can still write across collections.
  • The scoped-user fixtures moved into tests/test_authz/conftest.py and scope_helpers.py, so both scope suites share them.
  • Full backend suite: 2117 passed. The 15 failures also fail on origin/main: test_search (11), Sparx .eap (2) and test_mnemos (2).
  • Surface-parity check is clean.

Rollout

No migration is needed. Scoped users will now get per-item errors from batch calls that previously succeeded outside their scope. The anonymous relationship-reads PR (v6.50.3) and #301 (v6.51.0) are in flight, so whichever merges later needs a small CHANGELOG and version rebase.

ADR: docs/adrs/ADR-250-Batch-Endpoints-Enforce-Write-Scope.md
Spec: docs/adrs/specs/SPEC-250-A-Batch-Endpoints-Enforce-Write-Scope.md

🤖 Generated with Claude Code

https://claude.ai/code/session_01EbTwcTX1wKVooS7oWd7cP9

… (ADR-250)

None of the ten /api/batch/{elements,diagrams}/* endpoints checked
collection write-scope (ADR-237/238); only the ADR-249 relationship batch
did. A user scoped to collection A could delete, clone, retag, move, create
or update elements and diagrams in any other collection through them —
writes the single-item endpoints refuse with 403. Reproduced: a scoped
architect's batch writes into an out-of-scope collection all succeeded.

- batch/service.py: new _require_writable (assert_write_allowed -> per-item
  ValueError). Every batch function takes user=<dict> and gates each item
  before writing, matching its single-item endpoint: own collection for
  delete/tags/update/clone; current AND destination collection for set
  moves; the effective set's collection for create (ADR-238). The ADR-249
  relationship batch now uses the same helper.
- batch/router.py: passes user=current_user throughout.
- Out-of-scope items fail individually ("Outside your collection
  write-scope") and are left untouched; the rest of the batch runs.
  Unscoped users and admins unchanged.

No schema, endpoint, MCP tool, or CLI change.

Tests: tests/test_authz/test_batch_write_scope.py (new, TDD — all 11
scoped cases red before, green after; 2 bypass cases). Scoped-user fixtures
moved to tests/test_authz/conftest.py + scope_helpers.py (shared with
test_collection_scope.py). test_authz + test_batch + test_relationships:
93 passed. Surface parity clean.

See docs/adrs/ADR-250-Batch-Endpoints-Enforce-Write-Scope.md and
docs/adrs/specs/SPEC-250-A-Batch-Endpoints-Enforce-Write-Scope.md.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01EbTwcTX1wKVooS7oWd7cP9
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