Skip to content

Commit 549abb5

Browse files
authored
fix: REST API CSRF exempt list (#25590)
1 parent 512fb9a commit 549abb5

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

superset/views/base_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class BaseSupersetApi(BaseSupersetApiMixin, BaseApi):
251251
...
252252

253253

254-
class BaseSupersetModelRestApi(ModelRestApi, BaseSupersetApiMixin):
254+
class BaseSupersetModelRestApi(BaseSupersetApiMixin, ModelRestApi):
255255
"""
256256
Extends FAB's ModelResApi to implement specific superset generic functionality
257257
"""

tests/unit_tests/conftest.py

+9
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ def app(request: SubRequest) -> Iterator[SupersetApp]:
8989
app.config["TESTING"] = True
9090

9191
# loop over extra configs passed in by tests
92+
# and update the app config
93+
# to override the default configs use:
94+
#
95+
# @pytest.mark.parametrize(
96+
# "app",
97+
# [{"SOME_CONFIG": "SOME_VALUE"}],
98+
# indirect=True,
99+
# )
100+
# def test_some_test(app_context: None) -> None:
92101
if request and hasattr(request, "param"):
93102
for key, val in request.param.items():
94103
app.config[key] = val

tests/unit_tests/security/api_test.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
import pytest
18+
19+
from superset.extensions import csrf
20+
21+
22+
@pytest.mark.parametrize(
23+
"app",
24+
[{"WTF_CSRF_ENABLED": True}],
25+
indirect=True,
26+
)
27+
def test_csrf_not_exempt(app_context: None) -> None:
28+
"""
29+
Test that REST API is not exempt from CSRF.
30+
"""
31+
assert csrf._exempt_blueprints == {"MenuApi", "SecurityApi", "OpenApi"}

0 commit comments

Comments
 (0)