Skip to content

Fix JWT token generation with unset issuer/audience config#61278

Merged
potiuk merged 2 commits intoapache:mainfrom
amoghrajesh:bump-jwt
Jan 31, 2026
Merged

Fix JWT token generation with unset issuer/audience config#61278
potiuk merged 2 commits intoapache:mainfrom
amoghrajesh:bump-jwt

Conversation

@amoghrajesh
Copy link
Contributor


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

PyJWT released 2.11.0 https://pyjwt.readthedocs.io/en/stable/changelog.html#v2-11-0 which adds stricter validation for JWT claims.

The change: jpadilla/pyjwt#1039 and jpadilla/pyjwt#1040 ensures that the iss and aud claims must me StringOrURI as per RFC 7519: https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.1

An example of earlier behaviour with 2.10.1 pyjwt

jwt.encode({"iss": []}, key, algorithm="HS256")
Out[9]: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOltdfQ.-iVQNepE7AkWkxP2IyS2A8YlkvsSpgHKFoGElirCGSQ'
jwt.encode({"iss": 123}, "XdHWZSEDZw1KS+qP1ggxDQ==", algorithm="HS256") 
Out[10]: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOjEyM30.segFYHCUVHVGM6RbSGnqSJXnUNObaTwQGex_YMFn5IY'

With 2.11.0 pyjwt:

jwt.encode({"iss": 123}, "XdHWZSEDZw1KS+qP1ggxDQ==", algorithm="HS256") 
Traceback (most recent call last):
  File "/Users/amoghdesai/Documents/OSS/repos/airflow/.venv/lib/python3.13/site-packages/IPython/core/interactiveshell.py", line 3701, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-7-3b5e0f6758f3>", line 1, in <module>
    jwt.encode({"iss": 123}, "XdHWZSEDZw1KS+qP1ggxDQ==", algorithm="HS256")
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amoghdesai/Documents/OSS/repos/airflow/.venv/lib/python3.13/site-packages/jwt/api_jwt.py", line 145, in encode
    raise TypeError("Issuer (iss) must be a string.")
TypeError: Issuer (iss) must be a string.
jwt.encode({"iss": []}, key, algorithm="HS256")
Traceback (most recent call last):
  File "/Users/amoghdesai/Documents/OSS/repos/airflow/.venv/lib/python3.13/site-packages/IPython/core/interactiveshell.py", line 3701, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-8-320ea77fa0bd>", line 1, in <module>
    jwt.encode({"iss": []}, key, algorithm="HS256")
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amoghdesai/Documents/OSS/repos/airflow/.venv/lib/python3.13/site-packages/jwt/api_jwt.py", line 145, in encode
    raise TypeError("Issuer (iss) must be a string.")
TypeError: Issuer (iss) must be a string.

Now, airflow's config parser returned [] for unset configs when first_only was set. This is now rejected by PyJWT as invalid claims.

The fix is to return None for unset configs when single string is expected and for list values empty list is still valid -- this needs to be handled in the _conf_list_factory as well as the JWTGenerator to handle falsy values.


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@amoghrajesh amoghrajesh requested a review from vincbeck as a code owner January 31, 2026 05:08
@boring-cyborg boring-cyborg bot added the area:API Airflow's REST/HTTP API label Jan 31, 2026
@amoghrajesh amoghrajesh self-assigned this Jan 31, 2026
@tirkarthi
Copy link
Contributor

@amoghrajesh
Copy link
Contributor Author

Yep its likely that. I tried to resolve it

@amoghrajesh
Copy link
Contributor Author

@tirkarthi do you wanna take another look now? Mypy is fixed.

Copy link
Contributor

@tirkarthi tirkarthi left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @amoghrajesh .

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

Nice!

@potiuk potiuk merged commit a440d1d into apache:main Jan 31, 2026
131 checks passed
@bugraoz93
Copy link
Contributor

Nice, thanks @amoghrajesh!

morelgeorge pushed a commit to morelgeorge/airflow that referenced this pull request Feb 1, 2026
)

* Fix JWT token generation with unset issuer/audience config

* Fix JWT token generation with unset issuer/audience config
@bugraoz93
Copy link
Contributor

This needs a backport, seeing the similar issue. Will create in a moment

bugraoz93 pushed a commit to bugraoz93/airflow that referenced this pull request Feb 1, 2026
apache#61278)

* Fix JWT token generation with unset issuer/audience config

* Fix JWT token generation with unset issuer/audience config
(cherry picked from commit a440d1d)

Co-authored-by: Amogh Desai <[email protected]>
bugraoz93 added a commit that referenced this pull request Feb 1, 2026
#61278) (#61331)

* Fix JWT token generation with unset issuer/audience config
(cherry picked from commit a440d1d)

Co-authored-by: Amogh Desai <[email protected]>
@eladkal eladkal added this to the Airflow 3.1.8 milestone Feb 2, 2026
shashbha14 pushed a commit to shashbha14/airflow that referenced this pull request Feb 2, 2026
)

* Fix JWT token generation with unset issuer/audience config

* Fix JWT token generation with unset issuer/audience config
ephraimbuddy pushed a commit that referenced this pull request Feb 3, 2026
#61278) (#61331)

* Fix JWT token generation with unset issuer/audience config
(cherry picked from commit a440d1d)

Co-authored-by: Amogh Desai <[email protected]>
@eladkal
Copy link
Contributor

eladkal commented Feb 3, 2026

cc @ephraimbuddy given rc2 we need to change milestone on this PR to 3.1.7 right?

@ephraimbuddy
Copy link
Contributor

cc @ephraimbuddy given rc2 we need to change milestone on this PR to 3.1.7 right?

I have done so on the backport: #61331
Need to do same here too

potiuk pushed a commit that referenced this pull request Feb 3, 2026
* [v3-1-test] Add Keycloak token documentation to Security/API (#61228) (#61248)

(cherry picked from commit bb04b5d)

Co-authored-by: Bugra Ozturk <[email protected]>

* [v3-1-test] Fix language selector state not updating on change (#61060) (#61263)

(cherry picked from commit 975cfe6)

* [v3-1-test] Clarify template context for asset-triggered DAGs in airflow-core docs (#61258) (#61282)

(cherry picked from commit f7aa502)

Co-authored-by: Rachana Dutta <[email protected]>
Co-authored-by: kevinhongzl <[email protected]>

* [v3-1-test] Fix flaky OTel integration test with DNS health check (#61070) (#61242) (#61286)

* Fix flaky OTel integration test with DNS health check (#61070)

* Update airflow-core/tests/integration/otel/test_otel.py



---------
(cherry picked from commit 8ac25dd)

Co-authored-by: Abhishek Mishra <[email protected]>
Co-authored-by: Henry Chen <[email protected]>

* [v3-1-test] Update pmc verification docs (#61271) (#61294)

* Update Helm Chart release instructions for PMC Checks

* Update KEY download instructions for PMC Checks

* Update dev/README_RELEASE_HELM_CHART.md
(cherry picked from commit c74b24a)

* [v3-1-test] update version for release command (#61260) (#61328)

(cherry picked from commit 7790482)

Co-authored-by: Rahul Vats <[email protected]>

* CI: Upgrade important CI environment (#61327)

* [v3-1-test] Fix JWT token generation with unset issuer/audience config (#61278) (#61331)

* Fix JWT token generation with unset issuer/audience config
(cherry picked from commit a440d1d)

Co-authored-by: Amogh Desai <[email protected]>

* [v3-1-test] Remove empty `apache_airflow_site.py` file (#61308)
(cherry picked from commit d65ff01)

Co-authored-by: Jed Cunningham <[email protected]>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bugra Ozturk <[email protected]>
Co-authored-by: Guan-Ming (Wesley) Chiu <[email protected]>
Co-authored-by: Shahar Epstein <[email protected]>
Co-authored-by: Rachana Dutta <[email protected]>
Co-authored-by: kevinhongzl <[email protected]>
Co-authored-by: Abhishek Mishra <[email protected]>
Co-authored-by: Henry Chen <[email protected]>
Co-authored-by: Rahul Vats <[email protected]>
Co-authored-by: Amogh Desai <[email protected]>
Co-authored-by: Jed Cunningham <[email protected]>
jason810496 pushed a commit to abhijeets25012-tech/airflow that referenced this pull request Feb 3, 2026
)

* Fix JWT token generation with unset issuer/audience config

* Fix JWT token generation with unset issuer/audience config
jhgoebbert pushed a commit to jhgoebbert/airflow_Owen-CH-Leung that referenced this pull request Feb 8, 2026
)

* Fix JWT token generation with unset issuer/audience config

* Fix JWT token generation with unset issuer/audience config
choo121600 pushed a commit to choo121600/airflow that referenced this pull request Feb 22, 2026
)

* Fix JWT token generation with unset issuer/audience config

* Fix JWT token generation with unset issuer/audience config
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.

7 participants