Aerostack
security

sec-jwt-verify Edge Function — Security

Security

Verifies a JWT token signature and expiry using HMAC-SHA256 or HMAC-SHA512 via Web Crypto — zero dependencies.

navin @navin verified
Updated Mar 12, 2026
GitHub

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.

terminal — aerostack cli
$ npx aerostack add navin/sec-jwt-verify
smart_toy

Use with AI Assistants

MCP

Connect 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.

claude_desktop_config.json
{
  "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
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: true means the signature was valid but exp has passed — useful for distinguishing tampering from timeout
  • Uses timing-safe crypto.subtle.verify — not vulnerable to timing attacks
  • Pair with sec-jwt-sign to create and consume tokens with the same secret

Metadata

upgrade Version 1.0.0
gavel License MIT
language Language typescript
cloud Provider aerostack

Tags

security
deployed_code

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 →

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.