set Secure flag on keycloak login cookies behind a TLS proxy#69594
Merged
Conversation
vincbeck
approved these changes
Jul 8, 2026
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.
The keycloak auth manager sets the session JWT, the OIDC id token, and the OAuth state cookie during login, and it decides the cookie Secure flag from
secure = bool(conf.get("api", "ssl_cert")). That drops therequest.base_url.scheme == "https"term the rest of the codebase uses for the same decision, includinglogout_callbacka few lines down, the core auth manager login/logout, and the refresh-token middleware. When the api-server sits behind a proxy that terminates TLS,ssl_certis normally unset in Airflow, so with the current check these auth cookies go out without Secure even though the browser reached the server over HTTPS. A browser will then also attach them to a plaintext http:// request to the same host, which puts the session token within reach of a network or SSL-stripping attacker. I noticed it while comparing the login and logout handlers in this file, since logout already guards on the request scheme. This lines both login routes up with that canonical form so the cookies carry Secure behind a proxy, and nothing changes when Airflow terminates TLS itself or serves plain HTTP.