You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JSON Error When Decoding JWT with Nested Object in sub Claim
When decoding a JWT with a nested object in the sub claim, jsonwebtoken fails with the error Error::Json("expected ',' or '}'", line: 1, column: 8), despite the JSON payload being valid and manually deserializable.
Steps to Reproduce
Use jsonwebtoken version 9.3.0 (also tested with 8.x).
Define a claim struct with a nested object in sub:
use serde::{Serialize,Deserialize};#[derive(Debug,Serialize,Deserialize)]#[serde(rename_all = "camelCase")]structSubClaims{user_id:i32,tenant_name:String,tenant_id:i32,}#[derive(Debug,Serialize,Deserialize)]structClaims{sub:SubClaims,exp:usize,iss:String,aud:String,}
The issue likely stems from jsonwebtoken passing an incorrect or truncated byte slice to serde_json::from_slice when deserializing a nested object in sub, or from a deserialization incompatibility with complex structures.
Request
Please investigate why jsonwebtoken::decode fails with nested objects in sub and provide a fix or clarification on whether complex sub claims are supported.
The text was updated successfully, but these errors were encountered:
JSON Error When Decoding JWT with Nested Object in
sub
ClaimWhen decoding a JWT with a nested object in the
sub
claim,jsonwebtoken
fails with the errorError::Json("expected ',' or '}'", line: 1, column: 8)
, despite the JSON payload being valid and manually deserializable.Steps to Reproduce
jsonwebtoken
version 9.3.0 (also tested with 8.x).sub
:HS256
(orHS512
):Expected Behavior
The token should decode successfully into the
Claims
struct.Actual Behavior
Decoding fails with
Error::Json("expected ',' or '}'", line: 1, column: 8)
.Additional Notes
serde_json::from_str
andserde_json::from_slice
works correctly:sub
claim (e.g.,sub: String
):HS256
,HS512
, and older versions ofjsonwebtoken
(8.x).URL_SAFE_NO_PAD
for Base64 decoding (correct) andserde_json::from_slice
for deserialization.Environment
Possible Cause
The issue likely stems from
jsonwebtoken
passing an incorrect or truncated byte slice toserde_json::from_slice
when deserializing a nested object insub
, or from a deserialization incompatibility with complex structures.Request
Please investigate why
jsonwebtoken::decode
fails with nested objects insub
and provide a fix or clarification on whether complexsub
claims are supported.The text was updated successfully, but these errors were encountered: