Repository navigation
Scope API tokens to the queries shared with them - #724
Open
chrisclark wants to merge 1 commit into
Open
chrisclark wants to merge 1 commit into
chrisclark wants to merge 1 commit into
Conversation
view_permission() ORed the permission predicate together with the token check, and DownloadQueryView and StreamQueryView both use view_permission. A valid token therefore satisfied the permission check on its own, so any token holder could read any saved query -- /explorer/1/download, /explorer/2/download, ... -- rather than only the queries the token was issued for. EXPLORER_USER_QUERY_VIEWS, the documented mechanism for sharing selected queries, was not consulted. The token is a server-wide credential rather than a user, so it can only ever say "this caller is allowed to use the API", never "and nothing about which queries". Token access now goes through token_can_see_query, which limits it to the queries in EXPLORER_USER_QUERY_VIEWS when that setting is configured. Installs that do not configure EXPLORER_USER_QUERY_VIEWS have no shareable-queries list to scope against, so they keep the documented behaviour of tokens reaching any query id. That keeps existing token-as-data-API integrations working; the bypass above is closed for every install that does use the feature.
This branch has not been deployed
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.
Summary
Fixes the API token bypassing the permission check. High.
view_permission()ORed the permission predicate together with the token check:DownloadQueryViewandStreamQueryViewboth useview_permission, so a valid token satisfied the permission check on its own. Any token holder could read any saved query by walking ids (/explorer/1/download,/2/download, ...), rather than only the queries the token was issued for.EXPLORER_USER_QUERY_VIEWS, the documented mechanism for sharing selected queries, was not consulted on these paths at all.Worth noting
explorer/permissions.pyalready documents "token auth does not give you permission to view the list" forview_permission_list— the per-query paths were missing that same treatment.Fix
A token is a server-wide credential rather than a user, so it can only ever establish "this caller may use the API", never "and here is what they may read." Token access now goes through
token_can_see_query(), which limits it to the queries inEXPLORER_USER_QUERY_VIEWSwhen that setting is configured.Backwards compatibility was an explicit decision here. Installs that do not configure
EXPLORER_USER_QUERY_VIEWShave no shareable-queries list to scope against, so they keep the documented behaviour of a token reaching any query id. That keeps existing token-as-data-API integrations working, while the bypass is closed for every install that actually uses the sharing feature. If you would prefer the strict version (token must pass the same per-query check as users, breaking any integration that relies on unscoped access), it is a one-line change intoken_can_see_query— say the word.Tests
New
TestTokenAuthScopeclass:EXPLORER_USER_QUERY_VIEWSis empty.Full suite: 300 tests, OK.
ruff check explorer/: clean.