Skip to content

Commit 012bfb5

Browse files
[v3-0-test] Sanitize Username (#52419) (#52421)
Escape user.username in flash banners to prevent potential HTML injection (cherry picked from commit fb94109) Co-authored-by: bu <[email protected]>
1 parent 7ab6f05 commit 012bfb5

File tree

1 file changed

+5
-3
lines changed
  • providers/fab/src/airflow/providers/fab/auth_manager/security_manager

1 file changed

+5
-3
lines changed

providers/fab/src/airflow/providers/fab/auth_manager/security_manager/override.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
from flask_jwt_extended import JWTManager
6262
from flask_login import LoginManager
6363
from itsdangerous import want_bytes
64-
from markupsafe import Markup
64+
from markupsafe import Markup, escape
6565
from sqlalchemy import func, inspect, or_, select
6666
from sqlalchemy.exc import MultipleResultsFound
6767
from sqlalchemy.orm import joinedload
@@ -539,8 +539,9 @@ def reset_user_sessions(self, user: User) -> None:
539539
user_session_model = interface.sql_session_model
540540
num_sessions = session.query(user_session_model).count()
541541
if num_sessions > MAX_NUM_DATABASE_USER_SESSIONS:
542+
safe_username = escape(user.username)
542543
self._cli_safe_flash(
543-
f"The old sessions for user {user.username} have <b>NOT</b> been deleted!<br>"
544+
f"The old sessions for user {safe_username} have <b>NOT</b> been deleted!<br>"
544545
f"You have a lot ({num_sessions}) of user sessions in the 'SESSIONS' table in "
545546
f"your database.<br> "
546547
"This indicates that this deployment might have an automated API calls that create "
@@ -557,9 +558,10 @@ def reset_user_sessions(self, user: User) -> None:
557558
session.delete(s)
558559
session.commit()
559560
else:
561+
safe_username = escape(user.username)
560562
self._cli_safe_flash(
561563
"Since you are using `securecookie` session backend mechanism, we cannot prevent "
562-
f"some old sessions for user {user.username} to be reused.<br> If you want to make sure "
564+
f"some old sessions for user {safe_username} to be reused.<br> If you want to make sure "
563565
"that the user is logged out from all sessions, you should consider using "
564566
"`database` session backend mechanism.<br> You can also change the 'secret_key` "
565567
"webserver configuration for all your webserver instances and restart the webserver. "

0 commit comments

Comments
 (0)