ruby-jwt icon indicating copy to clipboard operation
ruby-jwt copied to clipboard

Possibility to override the alg header when encoding tokens

Open anakinj opened this issue 2 years ago • 2 comments
trafficstars

Currently it's not possible to override the alg header value using the header parameter. To me it seems intuitive not to touch the user specified values and just go with them.

Suggestion is to not to populate the alg header if that is already given by the user.

anakinj avatar Mar 25 '23 08:03 anakinj

From what I understand this would be a massive security issue.

"The widest known issue is probably that the header allows for a[n] alg claim to specify which algorithm was used to sign the token. Bad implementations would (by default) use this claim to choose how to verify the token; which means an attacker could simply put "alg":"none" , claim to be the most super of admins, and the application would accept those claims and grant all the access." [Source]

codespearhead avatar Jan 15 '24 20:01 codespearhead

That would for sure be a big problem. Changed the subject to hopefully be a bit clearer what the scope is.

The intention here is to preserve the user defined alg value passed to the encoding logic. Currently the alg value is always taken from the used algorithm, but the user provided value could as well just be used.

For example:

JWT.encode(payload, key, 'HS256', header_fields={alg: 'CustomALG'})

anakinj avatar Jan 15 '24 21:01 anakinj