sec-jwt-verify Edge Function — Security
SecurityVerifies a JWT token signature and expiry using HMAC-SHA256 or HMAC-SHA512 via Web Crypto — zero dependencies.
Edge function sec-jwt-verify Verifies a JWT token signature and expiry using HMAC-SHA256 or HMAC-SHA512 via Web Crypto — zero dependencies.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.
npx aerostack add navin/sec-jwt-verify Use with AI Assistants
MCPConnect Claude, Cursor, or any MCP-compatible client — then call this function by slug
① Add MCP Server
Add this once — access all Aerostack functions from your AI tool.
{
"mcpServers": {
"aerostack": {
"url": "https://mcp.aerostack.dev",
"type": "http"
}
}
} ② Call this function
Ask your AI to use the call_function tool with this slug:
call_function({
slug: "sec-jwt-verify",
args: {
"token": "example_token",
"secret": "example_secret",
"algorithm": "HS256"
}
}) sec-jwt-verify — Verify JWT token signatures
Validates a JWT's HMAC signature and expiry claim using Web Crypto — never throws, always returns a structured result.
API
POST /api/sec-jwt-verify
Request body
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
token |
string | ✅ | — | The JWT string to verify |
secret |
string | ✅ | — | HMAC secret used to sign the token |
algorithm |
"HS256" | "HS512" |
❌ | "HS256" |
Expected algorithm |
Success response (200)
{
"success": true,
"data": {
"valid": true,
"expired": false,
"payload": { "sub": "user123", "iat": 1709000000, "exp": 1709003600 }
}
}
Error responses
| Code | HTTP | When |
|---|---|---|
INVALID_INPUT |
400 | Missing required field |
INTERNAL_ERROR |
500 | Unexpected error |
Usage
cURL
curl -X POST "$FUNCTION_URL" \
-H "Content-Type: application/json" \
-d '{"token": "eyJ...", "secret": "my-secret"}'
TypeScript / JavaScript (HTTP)
const response = await fetch(FUNCTION_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token: req.headers.authorization?.split(' ')[1], secret: JWT_SECRET }),
});
const { data } = await response.json();
if (!data.valid) throw new Error('Unauthorized');
const userId = data.payload.sub;
Direct import (Node / Bun / Deno)
import { jwtVerify } from '@aerostack/functions/sec-jwt-verify';
const { valid, expired, payload } = await jwtVerify({
token: bearerToken,
secret: process.env.JWT_SECRET!,
});
Use Cases
- Validating Bearer tokens in API route middleware
- Checking session tokens without maintaining server-side session state
- Verifying signed invite or magic-link tokens before granting access
- Inspecting JWT claims to make authorization decisions (roles, scopes)
Notes
- Never throws — all failure modes return
{ valid: false, expired: false, payload: null } expired: truemeans the signature was valid butexphas passed — useful for distinguishing tampering from timeout- Uses timing-safe
crypto.subtle.verify— not vulnerable to timing attacks - Pair with
sec-jwt-signto create and consume tokens with the same secret
Metadata
Tags
Publisher
@navin verified
Build and publish your own functions
Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.
More Security Functions
Browse Security Functions →sec-api-key-generate
by @navin
Generates a cryptographically random API key with a custom prefix using a base62 alphabet — no ambiguous characters, URL-safe.
sec-cors-validate
by @navin
Validates a request Origin against an allow list and returns the correct CORS response headers to set — supports wildcards and credentials.
sec-csp-generate
by @navin
Generates a Content-Security-Policy header value from a structured directives object — supports report-only mode and report-uri.
sec-decrypt-aes
by @navin
Decrypts an AES-256-GCM encrypted bundle produced by sec-encrypt-aes — key is derived via SHA-256, auth tag is verified automatically.
sec-encrypt-aes
by @navin
Encrypts a string with AES-256-GCM using Web Crypto — key is derived via SHA-256, output is a portable IV:ciphertext bundle.
sec-hash-sha256
by @navin
Hashes a string using SHA-256 via the Web Crypto API. Supports hex and base64 output. Zero dependencies.
Frequently asked questions
What does the sec-jwt-verify function do? +
sec-jwt-verify is a serverless edge function for security automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.
How do I deploy the sec-jwt-verify function? +
Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/sec-jwt-verify ``` It will be live on Cloudflare Workers in seconds.
What runtime does sec-jwt-verify use? +
sec-jwt-verify runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.
Can I customise the sec-jwt-verify function? +
Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.