Skip to content

Commit 08f4783

Browse files
committed
feat: implement brefore_request to handle CSRF exemption logic.
Signed-off-by: sudipto baral <sudiptobaral.me@gmail.com>
1 parent db8ee3e commit 08f4783

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

airflow/www/app.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from datetime import timedelta
2222

2323
import connexion
24+
from flask import request
2425
from flask_appbuilder import SQLA
2526
from flask_wtf.csrf import CSRFProtect
2627
from markupsafe import Markup
@@ -73,6 +74,15 @@ def create_app(config=None, testing=False):
7374
"""Create a new instance of Airflow WWW app."""
7475
connexion_app = connexion.FlaskApp(__name__)
7576

77+
@connexion_app.app.before_request
78+
def before_request():
79+
"""Exempts the view function associated with '/api/v1' requests from CSRF protection."""
80+
if request.path.startswith("/api/v1"): # TODO: make sure this path is correct
81+
view_function = flask_app.view_functions.get(request.endpoint)
82+
if view_function:
83+
# Exempt the view function from CSRF protection
84+
connexion_app.app.extensions["csrf"].exempt(view_function)
85+
7686
connexion_app.add_middleware(
7787
CORSMiddleware,
7888
connexion.middleware.MiddlewarePosition.BEFORE_ROUTING,

0 commit comments

Comments
 (0)