Require trust sentinel for state.user injection in get_user()#66562
Merged
potiuk merged 1 commit intoMay 7, 2026
Conversation
The `get_user()` auth dependency in `core_api/security.py` accepted any value at `request.state.user` without verification, returning it before JWT signature/expiry/revocation checks. The only legitimate writer (`JWTRefreshMiddleware`) is one of many possible middlewares — any plugin or unrelated middleware that wrote `request.state.user`, accidentally or otherwise, would silently bypass JWT validation. Defense-in-depth: introduce a private module-level sentinel `USER_INJECTED_BY_TRUSTED_MIDDLEWARE` and require it to be set at `request.state.user_authenticated_via` for `get_user()` to honour the cached user. JWTRefreshMiddleware now stamps the marker alongside the user. Without the marker `get_user()` falls through to fresh JWT validation, so a stray `state.user = ...` write no longer skips auth. This does not defend against a *malicious* in-process plugin (which can import the sentinel and set it itself); plugins are trusted code in Airflow's security model. The goal is preventing accidental writes from unrelated middleware silently bypassing auth, which the audit flagged as an undocumented authentication pathway. Tests cover both the marked-honoured path and the unmarked-fall-through path; the JWTRefreshMiddleware test asserts the marker is stamped. Reported by the L3 ASVS sweep at apache/tooling-agents#23 (FINDING-133).
Contributor
|
Does it make it more secure? Any other middleware could also set manually this |
Member
Author
It's really so called "defense-in-depth" - of somebody adds a middleware that will inject a user, it won't work So this is not fixing a security issue per se, but makes the architecture more resilient in case deployment manager makes a mistake. |
Contributor
|
I see 👌 |
vincbeck
approved these changes
May 7, 2026
bugraoz93
approved these changes
May 7, 2026
jason810496
pushed a commit
to jason810496/airflow
that referenced
this pull request
May 11, 2026
…#66562) The `get_user()` auth dependency in `core_api/security.py` accepted any value at `request.state.user` without verification, returning it before JWT signature/expiry/revocation checks. The only legitimate writer (`JWTRefreshMiddleware`) is one of many possible middlewares — any plugin or unrelated middleware that wrote `request.state.user`, accidentally or otherwise, would silently bypass JWT validation. Defense-in-depth: introduce a private module-level sentinel `USER_INJECTED_BY_TRUSTED_MIDDLEWARE` and require it to be set at `request.state.user_authenticated_via` for `get_user()` to honour the cached user. JWTRefreshMiddleware now stamps the marker alongside the user. Without the marker `get_user()` falls through to fresh JWT validation, so a stray `state.user = ...` write no longer skips auth. This does not defend against a *malicious* in-process plugin (which can import the sentinel and set it itself); plugins are trusted code in Airflow's security model. The goal is preventing accidental writes from unrelated middleware silently bypassing auth, which the audit flagged as an undocumented authentication pathway. Tests cover both the marked-honoured path and the unmarked-fall-through path; the JWTRefreshMiddleware test asserts the marker is stamped. Reported by the L3 ASVS sweep at apache/tooling-agents#23 (FINDING-133).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
get_user()auth dependency incore_api/security.pyaccepted any value atrequest.state.userwithout verification, returning it before JWT signature/expiry/revocation checks. The only legitimate writer (JWTRefreshMiddleware) is one of many possible middlewares — any plugin or unrelated middleware that wroterequest.state.user, accidentally or otherwise, would silently bypass JWT validation.Fix
Defense-in-depth: introduce a private module-level sentinel
USER_INJECTED_BY_TRUSTED_MIDDLEWAREand require it to be set atrequest.state.user_authenticated_viaforget_user()to honour the cached user.JWTRefreshMiddlewarenow stamps the marker alongside the user. Without the marker,get_user()falls through to fresh JWT validation, so a straystate.user = ...write no longer skips auth.Threat model
This does not defend against a malicious in-process plugin (which can import the sentinel and set it itself) — plugins are trusted code in Airflow's security model. The goal is preventing accidental writes from unrelated middleware silently bypassing auth, which the audit flagged as an undocumented authentication pathway.
Tests cover both the marked-honoured path and the unmarked-fall-through path; the
JWTRefreshMiddlewaretest asserts the marker is stamped.Reported by
L3 ASVS sweep — apache/tooling-agents#23 (FINDING-133).
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.7) following the guidelines