Repository navigation
fix(v6.50.2): batch endpoints enforce collection write-scope per item (ADR-250) - #302
Merged
Merged
Conversation
… (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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
POST /api/elementsdoes (ADR-238).Outside your collection write-scopeand are left untouched. The rest of the batch still runs._require_writable, is shared by all eleven batch operations. The relationship batch now uses it too instead of its own inline copy.Tests
backend/tests/test_authz/test_batch_write_scope.py, written first:tests/test_authz/conftest.pyandscope_helpers.py, so both scope suites share them.origin/main:test_search(11), Sparx.eap(2) andtest_mnemos(2).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.mdSpec:
docs/adrs/specs/SPEC-250-A-Batch-Endpoints-Enforce-Write-Scope.md🤖 Generated with Claude Code
https://claude.ai/code/session_01EbTwcTX1wKVooS7oWd7cP9