Urgent.News

What's breaking now, across hundreds of outlets.

Tech

How to Generate a JWT Secret the Right Way (2026)

A JSON Web Token is only as strong as the secret that signs it. Most guides show a single command and move on, but three details decide whether the result is safe in production: how many bytes the key really has, how it is encoded when you store it, and where it lives. 1. The size rule is about bytes, not characters RFC 7518 section 3.2 requires an HMAC key at least as large as the hash output.…

JSON Web Tokens (JWTs) rely on a secret key for security. The strength of a JWT depends on three factors: key size, encoding method, and storage location.

For HS256, HS384, and HS512 algorithms, the key must be at least 32, 48, and 64 random bytes respectively. These byte counts translate to 64, 96, and 128 hex characters, or 43, 64, and 86 Base64URL characters. Many projects mistakenly use a "32-character secret," which only provides 16 bytes if the characters are ASCII only. Check your library to see if it decodes the hex string or uses the bytes as-is.

Encoding impacts storage but not the token verification. Hex is universally compatible but doubles the size. Standard Base64 contains characters like + and / that require quoting, while Base64URL replaces those with - and _, making it ideal for environments and headers. Whatever method you choose, both signing and verifying services must handle it identically.

The generation aspect is straightforward, but storage is crucial. Storing the secret in version control is risky and requires frequent rotation. The simplest approach is to load an environment variable from a .env file stored in .gitignore, with an accompanying .env.example containing just the variable name. A production setup should use a secret manager like Vault or a platform-specific encrypted environment store, with access restricted to signing and verifying services.

Implement key rotation by adding a key ID (kid) header, mapping each kid to its corresponding key, signing new tokens with the new key while keeping old tokens valid, and retiring the old key after the longest token validity period. Short-lived access tokens (5-15 minutes) simplify rotation, whereas long-lived tokens (weeks) make it challenging.

If a website generates the key for you, verify its safety by checking if the key is sent to a server. Use browser developer tools to inspect network requests and source code for any instances of the key. Avoid using secrets generated on the website itself.

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

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

I fetched 30 landing pages without JavaScript. 6 refused to answer.

I fetched 30 creator-economy landing pages with JavaScript disabled. Six of them refused to answer at all. Not "rendered badly". Refused: HTTP 403 or 429 to a plain, honestly-identified HTTP client.

  • Six landing pages failed to respond to unadorned HTTP requests
  • Evaluated 17 pages using 24-point checklist, scoring 29/35 on average
  • Common issues: overly long titles, missing JSON-LD structured data

Preventing Multi-Session Amnesia in Coding Agents: Prose Summaries vs. a 3-Artifact Shift-Handover Harness (-95.2% Input Tokens)

💡 AI Labo Benchmark Series — Experiment E36 (Multi-Session Continuity & State Handover) This post is part of our empirical benchmark series testing AI coding agent harness patterns inside…

  • UnstructuredSummaryHandoffRunner suffers from feature amnesia and premature victory
  • ShiftHandoverProtocolRunner employs 3-part artifact system for accurate handoff
  • 3-artifact method reduces input tokens by 95.2% and API costs by 83.1%

SLA vs SLO vs SLI Explained: Calculating 99.9% vs 99.99% Uptime

Teams routinely promise 99.99% uptime in customer contracts without checking what that actually means for deployment windows, database failovers, or third-party dependencies.

  • SLI measures raw metrics like HTTP request success rates
  • SLO sets internal targets for SLI metrics
  • SLA is external contract with financial consequences for SLO failures

More from Saturday, 28 November 2026 →