Skip to content

feat(vercel): one middleware for detection and clearance - #75

Merged
cport1 merged 1 commit into
mainfrom
feat/vercel-combined-middleware
Nov 10, 2026
Merged

cport1 merged 1 commit into
mainfrom
feat/vercel-combined-middleware

Conversation

@cport1

@cport1 cport1 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

What

A site on Vercel has one middleware file. Detection and the clearance gate used to be separate middlewares with separate credentials, and outside Next.js no middleware reported detections at all. This puts both in one middleware, configured from the environment.

  • @webdecoy/nextjs/vercel (new subpath). Default export: a ready middleware. Named: createVercelMiddleware(options).
  • @webdecoy/node/vercel: the default export now also reports detections when WEBDECOY_API_KEY is set. Without it, it is the clearance gate exactly as before. New named createVercelMiddleware(options); clearanceMiddleware() stays as the gate alone.
  • createDetectAndGate() in @webdecoy/node: the framework-free core both use.

Env: WEBDECOY_API_KEY (detection), WEBDECOY_SITE_KEY / WEBDECOY_SCANNER_ID / WEBDECOY_SENSOR_KEY (gate). Either half works without the other; with neither, every request passes. Detection is monitor mode by default; nothing throws.

Customer snippets

Next.js (middleware.ts, or proxy.ts on Next 16):

import webdecoy from '@webdecoy/nextjs/vercel';

export default webdecoy;

export const config = {
  matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};

Next 16 fails the build on export { default } from '@webdecoy/nextjs/vercel': its proxy/middleware export check reads the file's AST and does not count a re-exported default. Verified: Next 15.5 builds either form; Next 16.4 builds only the import-then-export form (in both proxy.ts and middleware.ts).

Astro / SvelteKit / Nuxt on Vercel (middleware.ts), unchanged from today:

export { default } from '@webdecoy/node/vercel';

export const config = {
  matcher: ['/((?!_astro/|_next/static/|favicon.ico|.*\\.(?:css|js|png|jpg|svg|webp|woff2?)$).*)'],
};

Details

  • Detection and the gate run concurrently, resolve one client IP (trustProxy 1) and see the same path, so a refusal's match key matches the request the detection reported. Tested by recomputing the key from the reported detection.
  • An enforced detection block answers before the gate. Otherwise the gate's response wins, and on continue the detection verdict is added to the gate's request headers (x-webdecoy-decision, x-webdecoy-detection-id, x-webdecoy-would-block), with inbound copies stripped.
  • A malformed key logs once and runs the gate alone.
  • Local analysis now forwards agents the bot registry names (e.g. ChatGPT-User with browser headers). This applies to every adapter.
  • typesVersions for vercel and testing subpaths: a Next 15 app with moduleResolution: node could not resolve the subpath's types.
  • gate.generated.js is unchanged.

Verification

  • npm run build, npm run lint (no new warnings), npm test (node 537, nextjs 21, all packages pass), npm run check:edge (all entries, including both new vercel.ts entries).
  • Packed tarballs installed into fresh Next 15.5 (middleware.ts, Edge runtime) and Next 16.4 (proxy.ts) apps. Both build. next start, then curl -A "WebDecoy-Test/1.0": the page sees x-webdecoy-would-block: true and a detection id; a browser request sees false, with a forged inbound header replaced.

@webdecoy/nextjs/vercel (new) and @webdecoy/node/vercel run detection and
the clearance gate together, configured from WEBDECOY_API_KEY and the three
clearance variables. With the API key set, bots and the WebDecoy-Test/
trigger are reported; without it @webdecoy/node/vercel is the gate alone,
unchanged. Monitor by default, fail open everywhere.

- createDetectAndGate() in @webdecoy/node is the framework-free core;
  createVercelMiddleware() wraps it for Vercel and for Next.js.
- Detection and the gate share one client IP and path, so a refusal's
  match key describes the same request the detection reported.
- Local analysis forwards agents the bot registry names.
- typesVersions for the vercel and testing subpaths.
@cport1
cport1 merged commit dbe3921 into main Nov 10, 2026
2 checks passed
@cport1
cport1 deleted the feat/vercel-combined-middleware branch November 10, 2026 17:17
@cport1 cport1 mentioned this pull request Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant