Generate a secure random CRON_SECRET for protecting cron endpoints. Created in your browser with copy-ready .env and code snippets.
CRON_SECRET is a random secret you store as an environment variable to protect scheduled (cron) endpoints. Your scheduler sends it with each request so the route can confirm the call is genuine and reject anything else. On Vercel, when CRON_SECRET is set, Cron jobs send it automatically as an Authorization Bearer header.
Two characters per byte. What openssl rand -hex prints.
32 bytes is 256 bits. Anything at or above 128 bits is already far beyond brute force.
Generated by your browser with the Web Crypto API. Nothing is sent to a server, nothing is stored, and reloading the page throws this value away.
CRON_SECRET=Goes in .env.local for local development and in your hosting provider environment variables for production. Never commit it.
// app/api/cron/route.ts
export async function GET(request: Request) {
const auth = request.headers.get('authorization');
if (auth !== `Bearer ${process.env.CRON_SECRET}`) {
return new Response('Unauthorized', { status: 401 });
}
// your scheduled work here
return Response.json({ ok: true });
}On Vercel, a Cron job sends this header automatically once CRON_SECRET is set. For a hardened comparison, use crypto.timingSafeEqual on equal-length buffers rather than !==.
openssl rand -hex 32
openssl rand -base64 32Same entropy, same source of randomness. Use whichever you trust more.
.env.local locally, your provider environment variables in production.| Option | Output | Entropy | Notes |
|---|---|---|---|
| 16 bytes, hex | 32 characters | 128 bits | Minimum for a cron secret |
| 32 bytes, hex | 64 characters | 256 bits | Recommended default |
| 32 bytes, base64url | 43 characters | 256 bits | Shorter, env and URL safe |
| 64 bytes, hex | 128 characters | 512 bits | Extra margin, rarely needed |
Formula
entropy (bits) = random bytes x 8random bytes = drawn from crypto.getRandomValues, a cryptographically secure source, not Math.random
bits of entropy = the real measure of guess resistance; 128 bits is already far beyond brute force
encoding = hex, base64url, or alphanumeric changes the character length, not the underlying entropy
Worked Example
A 32-byte secret in hex
Did you know? Math.random is not safe for secrets: it is a predictable pseudo-random generator that can be reverse-engineered from a few outputs. Web Crypto getRandomValues pulls from the operating system secure entropy pool, which is why every value here uses it.
Convert text to ASCII codes and back. Supports decimal, hex, binary, and octal formats.
Convert width/height to aspect ratios, scale dimensions, and generate responsive embed CSS for any layout.
Calculate required internet bandwidth based on devices and activities in your household.
Encode and decode Base64 strings. Convert text for data URIs, APIs, and safe data transmission.
Create CSS border-radius with visual controls for each corner. Generate circles, pills, and custom shapes.
Create CSS box shadows with multiple layers, live preview, and copy-ready code.