Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: query search low privileged user search access denied #11017

Merged
merged 1 commit into from
Sep 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2469,14 +2469,15 @@ def search_queries(self) -> FlaskResponse: # pylint: disable=no-self-use

:returns: Response with list of sql query dicts
"""
query = db.session.query(Query)
if security_manager.can_access_all_queries():
search_user_id = request.args.get("user_id")
elif (
request.args.get("user_id") is not None
and request.args.get("user_id") != g.user.get_user_id()
):
return Response(status=403, mimetype="application/json")
elif request.args.get("user_id") is not None:
try:
search_user_id = int(cast(int, request.args.get("user_id")))
except ValueError:
return Response(status=400, mimetype="application/json")
if search_user_id != g.user.get_user_id():
return Response(status=403, mimetype="application/json")
else:
search_user_id = g.user.get_user_id()
database_id = request.args.get("database_id")
Expand All @@ -2486,6 +2487,7 @@ def search_queries(self) -> FlaskResponse: # pylint: disable=no-self-use
from_time = request.args.get("from")
to_time = request.args.get("to")

query = db.session.query(Query)
if search_user_id:
# Filter on user_id
query = query.filter(Query.user_id == search_user_id)
Expand All @@ -2500,7 +2502,7 @@ def search_queries(self) -> FlaskResponse: # pylint: disable=no-self-use

if search_text:
# Filter on search text
query = query.filter(Query.sql.like("%{}%".format(search_text)))
query = query.filter(Query.sql.like(f"%{search_text}%"))

if from_time:
query = query.filter(Query.start_time > int(from_time))
Expand Down