Remy Blok
Remy Blok

Reputation: 137

Why is a JWT signature not unique for a specific payload

My application is using JWT and should prevent replay attacks. I was testing this an ran into the following.

When I have a valid JWT and change the last character of the token/signature the JWT is still valid. E.g. the following token do all validate correctly: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJTb21lIFRlc3QiLCJjbGFpbSI6IlNvbWUgQ2xhaW0ifQ.UkFYSK7hSSeiqUOSMdbXgbOErMFnuK0Emk1722ny-r4 eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJTb21lIFRlc3QiLCJjbGFpbSI6IlNvbWUgQ2xhaW0ifQ.UkFYSK7hSSeiqUOSMdbXgbOErMFnuK0Emk1722ny-r5 eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJTb21lIFRlc3QiLCJjbGFpbSI6IlNvbWUgQ2xhaW0ifQ.UkFYSK7hSSeiqUOSMdbXgbOErMFnuK0Emk1722ny-r6 eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJTb21lIFRlc3QiLCJjbGFpbSI6IlNvbWUgQ2xhaW0ifQ.UkFYSK7hSSeiqUOSMdbXgbOErMFnuK0Emk1722ny-r7

I have checked this on http://jwt.io/ and can be reproduced in my .Net application as well.

Can someone explain how it is possible that the signature is not unique for a given payload? I understand that collisions can occur, but I cannot explain that they are consecutive sequences.

Upvotes: 2

Views: 1383

Answers (2)

Brent Schmaltz
Brent Schmaltz

Reputation: 1161

When you change the signature (the last part) you can still decode the JWT to see the header and payload. However, if you attempt to validate the JWT with the changed signature, that validation will fail.

Upvotes: 0

pedrofb
pedrofb

Reputation: 39241

In this special case you are changing the base64 url encoding of the signature, not the signature itself

The fourth base64 values encode the same binary value. Try converting to hexadecimal at http://kjur.github.io/jsjws/tool_b64udec.html

The value you will see is

52415848aee14927a2a9439231d6d781b384acc167b8ad049a4d7bdb69f2fabe

If you change the suffix to -r1 or -r8 then the binary value changes and signature validation will fail

Can two different BASE 64 encoded strings result into same string if decoded?

Upvotes: 5

Related Questions