Menu

Your JWT secret is probably too short
📰

Your JWT secret is probably too short

#devcommunity#dev#secret#bytes#bits
Reading 0:00
15s threshold

Hi DEV, this is my first post. I'm a developer who builds websites, WordPress projects and browser extensions, and the topic comes from something I kept running into: JWT secrets that are far too weak.

The rule most people never read

If you sign tokens with HS256, the secret has to be at least as long as the hash output. That is 256 bits, or 32 bytes. This is not a tip, it is in the spec. RFC 7518, section 3.2, says a key of the same size as the hash output or larger MUST be used with HMAC-SHA2 algorithms.

So the same rule applies to the others:

Algorithm Minimum secret

HS256 256 bits (32 bytes)

HS384 384 bits (48 bytes)

HS512 512 bits (64 bytes)

Why a short secret is a real problem

A JWT is signed, not encrypted. Anyone who sees a token can copy it and try guessing the secret offline, as many times as they like, with no rate limit. Tools like hashcat have a mode just for this (-m 16500).

If your secret is secret, changeme or your app's name, it falls in seconds to a normal wordlist.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.