
Company News
Free Business Plan Upgrades for Open Source Maintainers
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.
@kakunin/middleware
Advanced tools
Express, Fastify, and Next.js middleware for Kakunin AI agent certificate enforcement
Express, Fastify, and Next.js middleware for Kakunin AI agent certificate enforcement.
Reads the X-Kakunin-Cert-Serial header, verifies the agent's certificate via the public Kakunin API, and rejects revoked, expired, or out-of-scope agents with a 403 before your route handler runs.
npm install @kakunin/middleware
import express from 'express';
import { kakuninGateway } from '@kakunin/middleware/express';
const app = express();
// Protect all routes — only certified agents pass
app.use(kakuninGateway({
requiredScope: 'transactions:write', // optional — enforce cert scope
cacheMs: 5000, // cache verify responses 5s (default)
}));
app.post('/trade', (req, res) => {
// req.kakunin is available — agent identity, scope, expiry
const { agent } = req.kakunin!;
res.json({ executed: true, by: agent?.name });
});
import Fastify from 'fastify';
import { kakuninPlugin } from '@kakunin/middleware/fastify';
const app = Fastify();
await app.register(kakuninPlugin, { requiredScope: 'transactions:write' });
app.post('/trade', async (req) => {
return { executed: true, by: req.kakunin?.agent?.name };
});
// middleware.ts
import { NextRequest, NextResponse } from 'next/server';
import { withKakunin } from '@kakunin/middleware/next';
export function middleware(req: NextRequest) {
return withKakunin(req, {
NextResponse,
requiredScope: 'transactions:write',
});
}
export const config = { matcher: ['/api/trade/:path*'] };
| Option | Type | Default | Description |
|---|---|---|---|
requiredScope | string | — | Required permitted_action value in the agent's cert scope |
cacheMs | number | 5000 | In-process cache TTL in ms. 0 = disabled |
verifyBaseUrl | string | https://kakunin.ai/api/v1/verify | Override for testing |
attachResult | boolean | true | Attach verify result to req.kakunin / request headers |
| Condition | Status | error field |
|---|---|---|
No X-Kakunin-Cert-Serial header | 401 | missing_cert_serial |
| Certificate serial not found | 403 | cert_not_found |
| Certificate revoked | 403 | agent_revoked |
| Certificate expired | 403 | agent_expired |
| Agent inactive/suspended | 403 | agent_inactive |
| Scope check failed | 403 | scope_violation |
| Verify API unreachable | 503 | verify_unavailable |
X-Kakunin-Cert-Serial from the inbound request headerGET https://kakunin.ai/api/v1/verify/{serial} (public endpoint, no API key)cacheMs milliseconds (cache hits are sub-1ms)valid: false or scope check failsThe verify endpoint is globally distributed and returns in under 500ms p99. With the default 5s cache, repeated requests from the same agent cost ~0ms after the first hit.
FAQs
Express, Fastify, and Next.js middleware for Kakunin AI agent certificate enforcement
We found that @kakunin/middleware demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.

Security News
During a UK cyber test, a Mythos 5 agent used sockpuppets, social engineering, and prompt injection to try to get a maintainer to merge malware.