Node-jsonwebtoken: Order of JSON key, value pairs

Created on 10 Dec 2015  路  1Comment  路  Source: auth0/node-jsonwebtoken

I'm not sure if this is a flaw in JWT specification or if I don't understand something. In JWT, the order of JSON key, value pairs matters when encoding and decoding tokens. Having {"alg": "HS256", "typ": "JWT"} headers produces different token compared to {"typ": "JWT", "alg": "HS256"}.

This seems weird to me because JSON specification states that the key, value pairs do not have an order: An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma). _source_.

jwt

Do you have an explanation for this?

Most helpful comment

Ok, I just figured out why this doesn't matter. As long as the secret is same, the token will work even though it looks different. The receiving part will use the secret to decode the token and even though the headers or payload are in different order, the end result is the same.

>All comments

Ok, I just figured out why this doesn't matter. As long as the secret is same, the token will work even though it looks different. The receiving part will use the secret to decode the token and even though the headers or payload are in different order, the end result is the same.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ehartford picture ehartford  路  3Comments

dwelle picture dwelle  路  3Comments

glowlabs picture glowlabs  路  3Comments

shea256 picture shea256  路  3Comments

Teebo picture Teebo  路  4Comments