Skip to content

Fix: Ensure JWTValidator handles GUESS algorithm with JWKS#63115

Open
henry3260 wants to merge 3 commits intoapache:mainfrom
henry3260:populate-jwks
Open

Fix: Ensure JWTValidator handles GUESS algorithm with JWKS#63115
henry3260 wants to merge 3 commits intoapache:mainfrom
henry3260:populate-jwks

Conversation

@henry3260
Copy link
Contributor

@henry3260 henry3260 commented Mar 8, 2026

What

  • Algorithm Detection: The alg is now dynamically read from the JWT header instead of relying on a predefined or mismatched algorithm.
  • Key Handling: The raw key (key.key) is passed directly to the jwt.decode function, avoiding conflicts caused by the PyJWK object enforcing its internal algorithm_name.

- Updated `avalidated_claims` to read the signing algorithm (`alg`) from the token header when `jwt_algorithm` is set to "GUESS".
- Passed the raw key (`key.key`) instead of the `PyJWK` object to prevent pyjwt from overriding the algorithm with `PyJWK.algorithm_name`.
Copilot AI review requested due to automatic review settings March 8, 2026 14:43
@henry3260 henry3260 requested a review from vincbeck as a code owner March 8, 2026 14:43
@boring-cyborg boring-cyborg bot added the area:API Airflow's REST/HTTP API label Mar 8, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the FastAPI JWT auth implementation so JWTValidator can validate tokens when [api_auth] jwt_algorithm = GUESS is used together with a configured JWKS (local/remote), and adds a unit test to cover that configuration.

Changes:

  • Allow JWTValidator to be constructed with algorithm=["GUESS"] when jwks is configured (previously rejected).
  • During validation, infer the concrete algorithm when using JWKS+GUESS so jwt.decode() can proceed.
  • Add a unit test exercising JWKS validation with jwt_algorithm=GUESS for RSA and Ed25519 keys.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
airflow-core/src/airflow/api_fastapi/auth/tokens.py Adjust JWT validation to support GUESS with JWKS by inferring an algorithm at decode time.
airflow-core/tests/unit/api_fastapi/auth/test_tokens.py Add regression test for JWKS validation when jwt_algorithm is set to GUESS.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Contributor

@SameerMesiah97 SameerMesiah97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there may be a security concern here because this loosens the restriction on what party decides the verification algorithm. I have left a comment at the most critical line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants