superset: Problem with PyJWT 2.10: `{'msg': 'Subject must be a string'}`
Bug description
When setting up a fresh sandbox environment, PyJWT 2.10 gets installed, released on Nov 17, i.e. three days ago. That breaks a little integration test suite we are running [^1]. This is the exception being raised:
AssertionError: {'msg': 'Subject must be a string'}
When downgrading to use pyjwt<2.10, the test suite succeeds again.
You may want to accompany this by potentially adjusting dependencies or code in Apache Superset?
[^1]: … which orchestrates CLI invocations of the superset program and HTTP calls to the Superset API, in order to validate it works well together with CrateDB.
Superset version
3.x and 4.x
Additional context
The software test suite maintained here can be used to reproduce the problem.
We added relevant details to this ticket, where we started to investigate this issue.
Checklist
- I have searched Superset docs and Slack and didn’t find a solution to my problem.
- I have searched the GitHub issue tracker and didn’t find a similar bug report.
- I have checked Superset’s logs for errors and if I found a relevant Python stacktrace, I included it here as text in the “additional context” section.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 5
- Comments: 18 (11 by maintainers)
Commits related to this issue
- Downgraded pyjwt from 2.10 to 2.9.0 pyjwt 2.10.x is buggy, here's a similar problem: https://github.com/apache/superset/issues/30995#issuecomment-2493546050 — committed to tomaszmrugalski/hevelius-backend by tomaszmrugalski 2 years ago
- Downgraded pyjwt from 2.10 to 2.9.0 pyjwt 2.10.x is buggy, here's a similar problem: https://github.com/apache/superset/issues/30995#issuecomment-2493546050 — committed to tomaszmrugalski/hevelius-backend by tomaszmrugalski 2 years ago
- Downgraded pyjwt from 2.10 to 2.9.0 pyjwt 2.10.x is buggy, here's a similar problem: https://github.com/apache/superset/issues/30995#issuecomment-2493546050 — committed to tomaszmrugalski/hevelius-backend by tomaszmrugalski 2 years ago
- jwt_require bug read more about it: https://github.com/apache/superset/issues/30995 — committed to JoHeyJo/recipe-backend by JoHeyJo 2 years ago
Have you configured flask-jwt-extended to not verify the sub claim? ‘JWT_VERIFY_SUB=False’
We just found this is most likely the root cause.
The canonical recommendation is to downgrade to PyJWT in the meanwhile.
app.config[“JWT_VERIFY_SUB”]=False
All right, I wasn’t aware that
JWT_VERIFY_SUB = Falsecould easily be configured within the Flask application configuration file, which is effectively thesuperset_config.pyfile in our case.After getting it right, this update perfectly resolves the problem we have been observing.
Thank you so much! 💯
Storing Object in
identityvs.additional_claims– Which is Better?Both approaches work, but the best choice depends on how you use the data. Here’s a breakdown of pros and cons for each approach.
1️⃣ Storing an Object in
identity✅ Pros:
✔ Simple & automatic retrieval –
get_jwt_identity()directly gives you the user object.✔ Easy for authentication – If
identityuniquely represents a user, it’s easier to work with.❌ Cons:
❌
"sub"is meant for a unique identifier, not a full object (not strictly JWT-compliant).❌ If you later need to change
"sub"behavior (e.g., switch to a UUID instead), it could cause compatibility issues.Retrieval
2️⃣ Storing Object Data in
additional_claims✅ Pros:
✔ Keeps
subclean –identityremains a single unique identifier (best practice).✔ More flexibility – You can store additional user-related data without overloading
"sub".✔ More readable JWT structure – Custom claims are explicitly separate from
"sub".❌ Cons:
❌ Requires an extra step to access the object (
get_jwt()instead ofget_jwt_identity()).❌ If you store too much data, the token size increases (which could be an issue for performance).
Retrieval
💡 Best Practice Recommendation
identityfor a single unique identifier (e.g.,user_id,email, orUUID).additional_claimsfor extra user attributes (e.g.,username,role,permissions).Best Approach (Combining Both)
Retrieving Data
When Should You Store the Full Object in
identity?When Should You Use
additional_claims?"sub"as a unique identifier."sub"to be a single value.🚀 Final Verdict
✅ Best Practice → Store a single unique ID in
identityand useadditional_claimsfor extra attributes.🔹 This approach is clean, scalable, and follows JWT best practices.
Hi @amotl , by any chance do we have steps documented for solution. how and where we can set configure ‘JWT_VERIFY_SUB’ to be False. getting error “Subject must be a string” while fetching CSRF token
Since my patch, this isn’t a problem with flask-jwt-extended anymore. If you don’t want enforce that the sub claim is a string, you just need to configure ‘JWT_VERIFY_SUB’ to be False. That’s your choice to make, not the library’s.
@jkogut: Do you have any idea why only we might be affected, but Superset’s test suite seems to still succeed, and nobody else seems to be tripped? Is it related to the value of the SECRET_KEY maybe?
That patch submitted by Dependabot also demonstrates the problem.