Skip to content

fix(transfer): run the bank-write validator on document import into an existing bank (#5137) - #5308

Merged
nicoloboschi merged 1 commit into
mainfrom
fix/5137-import-validator
Oct 6, 2026
Merged

nicoloboschi merged 1 commit into
mainfrom
fix/5137-import-validator

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

Fixes #5137.

Problem

Importing documents into a bank that already exists never reached an operation-validator hook. The only check on that path was validate_create_bank, which _ensure_bank_exists runs only when the bank is missing. So a validator that limits API keys to their own bank could not stop a key from merging an archive into another existing bank.

Fix

import_documents_async now calls validate_bank_write with a new BankWriteOperation.IMPORT_DOCUMENTS before doing anything else. That one method serves both routes that merge documents:

  • POST /v1/default/banks/{bank_id}/document-transfer (deprecated)
  • POST /v1/default/banks/{bank_id}/transfer/import?mode=merge

Restore mode (transfer/import, default) was already safe: it only writes a bank that does not exist yet, which validate_create_bank gates.

Tests

  • api-slim test_import_into_existing_bank_runs_bank_write_validator: importing into an existing, forbidden bank raises 403, the validator sees IMPORT_DOCUMENTS, and nothing is imported.
  • system story test_83_bank_scoped_import: a bank:<id> key imports into its own bank and is refused on the neighbour's bank through both routes; the neighbour stays empty. The test validator (server_extensions/tag_scope_validator.py) gains the bank:<id> rule for this.

Both tests fail without the fix.

Out of scope

The issue also mentions mental-models/{id}/history, which is already fixed on main by #3831. Separate operation names for export, audit logs and LLM requests would be a policy nice-to-have; those routes are already checked under GET_BANK_PROFILE.

…n existing bank (#5137)

Importing documents only reached an operation-validator hook when the target
bank did not exist yet (validate_create_bank inside _ensure_bank_exists). An
import into an existing bank reached none, so a validator that confines API
keys to their own bank never saw a key merging an archive into another bank.

import_documents_async now calls validate_bank_write with a new
BankWriteOperation.IMPORT_DOCUMENTS before anything else. It covers both
routes that merge documents: POST .../document-transfer and
POST .../transfer/import?mode=merge. Restore mode was already safe: it only
writes a bank that does not exist, which validate_create_bank gates.

Tests:
- api-slim: an import into an existing, forbidden bank raises 403, the
  validator sees IMPORT_DOCUMENTS, and nothing is imported.
- system story test_83: a bank:<id> key imports into its own bank and is
  refused on the neighbour's, through both routes; the neighbour stays empty.
  The test validator gains the bank:<id> rule for this.
@nicoloboschi
nicoloboschi merged commit 5088396 into main Oct 6, 2026
230 of 234 checks passed
@nicoloboschi
nicoloboschi deleted the fix/5137-import-validator branch October 6, 2026 15:09
This was referenced Oct 6, 2026
@nicoloboschi nicoloboschi mentioned this pull request Nov 3, 2026
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.

document-transfer import (existing bank) never reaches the operation validator; mental-model-history gap already fixed on main (#3831)

1 participant