dpgaspar commented on a change in pull request #10451:
URL:
https://github.com/apache/incubator-superset/pull/10451#discussion_r467825882
##########
File path: tests/query_context_tests.py
##########
@@ -172,13 +173,58 @@ def test_csv_response_format(self):
payload = get_query_context(table.name, table.id, table.type)
payload["result_format"] = ChartDataResultFormat.CSV.value
payload["queries"][0]["row_limit"] = 10
- query_context = QueryContext(**payload)
+ query_context = ChartDataQueryContextSchema().load(payload)
responses = query_context.get_payload()
self.assertEqual(len(responses), 1)
data = responses[0]["data"]
self.assertIn("name,sum__num\n", data)
self.assertEqual(len(data.split("\n")), 12)
+ def test_sql_injection_via_groupby(self):
+ """
+ Ensure that calling invalid columns names in groupby are caught
+ """
+ self.login(username="admin")
+ table_name = "birth_names"
+ table = self.get_table_by_name(table_name)
+ payload = get_query_context(table.name, table.id, table.type)
+ payload["queries"][0]["groupby"] = ["currentDatabase()"]
Review comment:
If `currentDatabase()` is a defined metric will it run ok?
##########
File path: tests/query_context_tests.py
##########
@@ -172,13 +173,58 @@ def test_csv_response_format(self):
payload = get_query_context(table.name, table.id, table.type)
payload["result_format"] = ChartDataResultFormat.CSV.value
payload["queries"][0]["row_limit"] = 10
- query_context = QueryContext(**payload)
+ query_context = ChartDataQueryContextSchema().load(payload)
responses = query_context.get_payload()
self.assertEqual(len(responses), 1)
data = responses[0]["data"]
self.assertIn("name,sum__num\n", data)
self.assertEqual(len(data.split("\n")), 12)
+ def test_sql_injection_via_groupby(self):
+ """
+ Ensure that calling invalid columns names in groupby are caught
+ """
+ self.login(username="admin")
+ table_name = "birth_names"
+ table = self.get_table_by_name(table_name)
+ payload = get_query_context(table.name, table.id, table.type)
+ payload["queries"][0]["groupby"] = ["currentDatabase()"]
+ query_context = ChartDataQueryContextSchema().load(payload)
+ query_payload = query_context.get_payload()
+ assert query_payload[0].get("error") is not None
+
+ def test_sql_injection_via_columns(self):
+ """
+ Ensure that calling invalid columns names in columns are caught
+ """
+ self.login(username="admin")
+ table_name = "birth_names"
+ table = self.get_table_by_name(table_name)
+ payload = get_query_context(table.name, table.id, table.type)
+ payload["queries"][0]["groupby"] = []
+ payload["queries"][0]["metrics"] = []
+ payload["queries"][0]["columns"] = ["*, 'extra'"]
+ query_context = ChartDataQueryContextSchema().load(payload)
+ query_payload = query_context.get_payload()
+ assert query_payload[0].get("error") is not None
+
+ def test_sql_injection_via_filters(self):
+ """
+ Ensure that calling invalid columns names in filters are caught
+ """
+ self.login(username="admin")
+ table_name = "birth_names"
+ table = self.get_table_by_name(table_name)
+ payload = get_query_context(table.name, table.id, table.type)
+ payload["queries"][0]["groupby"] = ["name"]
+ payload["queries"][0]["metrics"] = []
Review comment:
Are we able to deny an injected `metric`?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]