Skip to content

fix: enforce per-user authorization on /query_multiple - #302

Open
nangelovv wants to merge 1 commit into
danny-avila:mainfrom
nangelovv:fix/query-multiple-authorization
Open

fix: enforce per-user authorization on /query_multiple#302
nangelovv wants to merge 1 commit into
danny-avila:mainfrom
nangelovv:fix/query-multiple-authorization

Conversation

@nangelovv

Copy link
Copy Markdown

What

Add a per-user authorization filter to POST /query_multiple, matching the ownership check POST /query already performs.

Why

Fixes #301. /query_multiple filtered returned chunks by file_id only, so any authenticated caller could read another tenant's documents by supplying their file_id.

Change

After the similarity search, keep only chunks the requester owns:

authorized_documents = [
    (doc, score)
    for doc, score in documents
    if doc.metadata.get("user_id") in (None, user_authorized)
]

user_authorized is resolved with the existing get_user_id(request) helper. Unowned chunks (user_id is None) remain visible, matching /query. Returns 404 when nothing is authorized; logs the number of withheld chunks.

Testing

  • New tests/test_main.py::test_query_multiple_filters_unauthorized: a result set mixing the caller's chunk and another user's chunk returns only the caller's.
  • tests/test_main.py: 11 passed.

/query_multiple filtered the returned chunks by file_id only, with no user_id
check, so any authenticated caller could read another tenant's document text by
supplying their file_id. The single-file /query endpoint already performs this
ownership check, so /query_multiple was an inconsistent gap.

Filter the results to chunks the requester owns (user_id is None or matches the
authenticated identity), mirroring /query, and return 404 when nothing is
authorized.
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.

/query_multiple returns documents without an authorization check (cross-tenant IDOR)

1 participant