Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Your JWT Secret Is Probably Too Weak. Here Is the 30-Second Fix

"secret", "changeme" and "mysupersecretkey" are not keys. They are passwords, and passwords get cracked offline. Open the config of almost any tutorial project and you will find a line like this: const token = jwt.sign(payload, 'secret'); It works. Tokens are issued and verified. And it is one of the most common ways a JWT-based login gets taken over. Why a weak secret is a real vulnerability…

In the world of JWT authentication, using a weak secret is a significant vulnerability. The source material reveals that keys like "secret", "changeme", and "mysupersecretkey" are not suitable for security purposes; they are actually passwords that can be cracked offline. Many tutorial projects include lines like `const token = jwt.sign(payload, 'secret');`, which is a common way for JWT-based logins to be compromised.

The key issue with weak secrets is that anyone who obtains one valid token can test guesses for the secret offline without any interaction with your server, rate limits, or logs. A successful match means they can create any token they like, with any user ID and role. This is not just theoretical; weak signing keys are common in security labs and are routinely checked by scanners.

The JSON Web Algorithms specification (RFC 7518) specifies that for HS256, the key must be at least 256 bits (32 bytes), HS384 requires 384 bits (48 bytes), and HS512 needs 512 bits (64 bytes). These specifications refer to bits of key material, not the number of characters in a string. If a secret is a memorable phrase, it may not contain enough entropy, even if it is long.

To generate a strong secret, use a cryptographically secure random generator. Node.js: `console.log(crypto.randomBytes(32).toString('base64url'));` OpenSSL (terminal): `openssl rand -base64 32` Python: `print(secrets.token_urlsafe(32))`. Each of these commands prints a fresh, random 256-bit value. For HS384 or HS512, use 48 or 64 bytes, respectively.

If generating the secret manually is inconvenient, consider using a browser-based JWT Secret Key Generator, which creates the key locally without sending it anywhere. When implementing a JWT secret, check for randomness, length, and ensure it is not hardcoded or logged anywhere in your code. Rotate the secret if necessary, and always verify the algorithm when checking a token to prevent attackers from choosing the algorithm themselves.

Rewritten by urgent.news; may contain errors — check the original.

Read the original at dev.to →

Report a problem with this story

More in Tech

AutoSSL Quietly Dropped the Mail Name — a Cloudflare-Only Origin and the Move to DNS-01

A field story about a cPanel certificate that renewed on time and still broke every Outlook client — the port 80 rule almost nobody connects to mail — and the DNS-01 setup I now use for any origin…

  • Outlook client displays certificate warning due to missing mail name
  • AutoSSL issues certificate without mail name, causing warning
  • Resolving issue requires checking names served by mail ports

My first website was ugly, and it worked

My uncle gave our family a monitor when I was a kid, a huge beige box that sat next to our dial-up modem. Every night I sat through the screech and waited while pages loaded one strip at a time, and…

  • Child gifted a large beige monitor and dial-up modem
  • Created first website in Notepad with single index.html file
  • Transitioned from inline styling to external CSS for improved aesthetics

How Instagram Split One Database Into Thousands

Shard keys, logical shards, and the 64-bit photo ID that says when a photo was made and which shard holds it Two different photos. Two different databases. Both stamped with the same ID: 3.

  • Instagram's user base grew to 14 million in a year.
  • Database split into thousands for efficient data management.
  • Shard keys and 64-bit photo ID determined data distribution.

JWKS and `kid` Explained: How to Find the Key That Signed Your Token (and Spot a Leaked Private Key)

A practical guide to reading a jwks.json file, matching the right key, and checking it is safe to publish. Your API receives a token signed by an identity provider.

  • JSON Web Key (JWK) represents a single cryptographic key in JSON format per RFC 7517
  • JSON Web Key Set (JWKS) is a JSON object containing an array of JWKs published at public URLs
  • kid field in token header is used to find matching JWK in JWKS for signature verification

More from Saturday 21 November →