fix: enforce per-user authorization on /query_multiple - #302
Open
nangelovv wants to merge 1 commit into
Open
Conversation
/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.
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.
What
Add a per-user authorization filter to
POST /query_multiple, matching the ownership checkPOST /queryalready performs.Why
Fixes #301.
/query_multiplefiltered returned chunks byfile_idonly, so any authenticated caller could read another tenant's documents by supplying theirfile_id.Change
After the similarity search, keep only chunks the requester owns:
user_authorizedis resolved with the existingget_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
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.