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

Most upvoted comments

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.

pip install 'pyjwt<2.10'

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

app.config[“JWT_VERIFY_SUB”]=False

All right, I wasn’t aware that JWT_VERIFY_SUB = False could easily be configured within the Flask application configuration file, which is effectively the superset_config.py file in our case.

After getting it right, this update perfectly resolves the problem we have been observing.

Thank you so much! 💯

Storing Object in identity vs. 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

access_token = create_access_token(identity={"id": 123, "username": "johndoe", "role": "admin"})

✅ Pros:

✔ Simple & automatic retrieval – get_jwt_identity() directly gives you the user object.
✔ Easy for authentication – If identity uniquely 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

user = get_jwt_identity()  # Retrieves full object stored in "sub"

2️⃣ Storing Object Data in additional_claims

access_token = create_access_token(identity=123, additional_claims={"username": "johndoe", "role": "admin"})

✅ Pros:

✔ Keeps sub clean – identity remains 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 of get_jwt_identity()).
❌ If you store too much data, the token size increases (which could be an issue for performance).

Retrieval

claims = get_jwt()
user_id = claims["sub"]  # Retrieves the identity
username = claims["username"]
role = claims["role"]

💡 Best Practice Recommendation

  • ✅ Use identity for a single unique identifier (e.g., user_id, email, or UUID).
  • ✅ Use additional_claims for extra user attributes (e.g., username, role, permissions).

Best Approach (Combining Both)

access_token = create_access_token(
    identity=123,  # Store only user ID in sub
    additional_claims={"username": "johndoe", "role": "admin"}
)

Retrieving Data

claims = get_jwt()
user_id = claims["sub"]  # Best practice: keep it as an ID
username = claims.get("username")
role = claims.get("role")

When Should You Store the Full Object in identity?

  • If your app always needs the entire user object and you don’t care about strict JWT compliance.
  • If you want to minimize API/database calls and always retrieve full user info from the token.

When Should You Use additional_claims?

  • If you follow best practices by keeping "sub" as a unique identifier.
  • If you need flexibility to modify or expand JWT data later.
  • If you’re integrating with other services that expect "sub" to be a single value.

🚀 Final Verdict

✅ Best Practice → Store a single unique ID in identity and use additional_claims for 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.