This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 2423238295 Add backward compatibility to CSRF protection of `/logout` 
method (#40479)
2423238295 is described below

commit 242323829502eece2f6c7748cc9db051f9c247bc
Author: Shahar Epstein <[email protected]>
AuthorDate: Fri Jun 28 16:35:04 2024 +0300

    Add backward compatibility to CSRF protection of `/logout` method (#40479)
---
 .../fab/auth_manager/security_manager/override.py        | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/airflow/providers/fab/auth_manager/security_manager/override.py 
b/airflow/providers/fab/auth_manager/security_manager/override.py
index e993a929ab..736032a773 100644
--- a/airflow/providers/fab/auth_manager/security_manager/override.py
+++ b/airflow/providers/fab/auth_manager/security_manager/override.py
@@ -27,6 +27,7 @@ import warnings
 from typing import TYPE_CHECKING, Any, Callable, Collection, Container, 
Iterable, Sequence
 
 import jwt
+import packaging.version
 import re2
 from deprecated import deprecated
 from flask import flash, g, has_request_context, session
@@ -71,6 +72,7 @@ from sqlalchemy.exc import MultipleResultsFound
 from sqlalchemy.orm import Session, joinedload
 from werkzeug.security import check_password_hash, generate_password_hash
 
+from airflow import __version__ as airflow_version
 from airflow.auth.managers.utils.fab import get_method_from_fab_action_map
 from airflow.configuration import conf
 from airflow.exceptions import AirflowException, 
AirflowProviderDeprecationWarning, RemovedInAirflow3Warning
@@ -125,13 +127,21 @@ log = logging.getLogger(__name__)
 MAX_NUM_DATABASE_USER_SESSIONS = 50000
 
 
-# The following class patches the logout method within AuthView, so it only 
supports POST method
-# to make CSRF protection effective. You could remove the patch and configure 
it when it is supported
+# The following logic patches the logout method within AuthView, so it 
supports POST method
+# to make CSRF protection effective. It is backward-compatible with Airflow 
versions <= 2.9.2 as it still
+# allows utilizing the GET method for them.
+# You could remove the patch and configure it when it is supported
 # natively by Flask-AppBuilder 
(https://github.com/dpgaspar/Flask-AppBuilder/issues/2248)
+if 
packaging.version.parse(packaging.version.parse(airflow_version).base_version) 
<= packaging.version.parse(
+    "2.9.2"
+):
+    _methods = ["GET", "POST"]
+else:
+    _methods = ["POST"]
 
 
 class _ModifiedAuthView(AuthView):
-    @expose("/logout/", methods=["POST"])
+    @expose("/logout/", methods=_methods)
     def logout(self):
         return super().logout()
 

Reply via email to