Arcjet helps developers protect their apps in just a few lines of code. Bot detection. Rate limiting. Email validation. Attack protection. Data redaction. A developer-first approach to security.
This is the monorepo containing various Arcjet open source packages for JS.
Arcjet security features for protecting JS apps:
Content-Security-Policy
(CSP).Join our Discord server or reach out for support.
Read the docs at docs.arcjet.com.
This example will enable Arcjet bot protection across your entire Next.js application. Next.js middleware runs before every request, allowing Arcjet to protect your entire application before your code runs.
It will return a 403 Forbidden response for all requests from bots not in the allow list.
// middleware.ts
import arcjet, { ArcjetRuleResult, detectBot } from "@arcjet/next";
import { NextRequest, NextResponse } from "next/server";
export const config = {
// matcher tells Next.js which routes to run the middleware on.
// This runs the middleware on all routes except for static assets.
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
};
const aj = arcjet({
key: process.env.ARCJET_KEY!, // Get your site key from https://app.arcjet.com
rules: [
detectBot({
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
// Block all bots except the following
allow: [
"CATEGORY:SEARCH_ENGINE", // Google, Bing, etc
// Uncomment to allow these other common bot categories
// See the full list at https://arcjet.com/bot-list
//"CATEGORY:MONITOR", // Uptime monitoring services
//"CATEGORY:PREVIEW", // Link previews e.g. Slack, Discord
],
}),
],
});
function isSpoofed(result: ArcjetRuleResult) {
return (
// You probably don't want DRY_RUN rules resulting in a denial
// since they are generally used for evaluation purposes but you
// could log here.
result.state !== "DRY_RUN" &&
result.reason.isBot() &&
result.reason.isSpoofed()
);
}
export default async function middleware(request: NextRequest) {
const decision = await aj.protect(request);
// Bots not in the allow list will be blocked
if (decision.isDenied()) {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}
// Arcjet Pro plan verifies the authenticity of common bots using IP data.
// Verification isn't always possible, so we recommend checking the results
// separately.
// https://docs.arcjet.com/bot-protection/reference#bot-verification
if (decision.results.some(isSpoofed)) {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}
return NextResponse.next();
}
This simple Node.js server is protected with Arcjet bot protection. It will return a 403 Forbidden response for all requests from bots not in the allow list.
// server.ts
import arcjet, { detectBot } from "@arcjet/node";
import http from "node:http";
const aj = arcjet({
key: process.env.ARCJET_KEY!, // Get your site key from https://app.arcjet.com
rules: [
detectBot({
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
// configured with a list of bots to allow from
// https://arcjet.com/bot-list
// Block all bots except the following
allow: [
"CATEGORY:SEARCH_ENGINE", // Google, Bing, etc
// Uncomment to allow these other common bot categories
// See the full list at https://arcjet.com/bot-list
//"CATEGORY:MONITOR", // Uptime monitoring services
//"CATEGORY:PREVIEW", // Link previews e.g. Slack, Discord
],
}),
],
});
const server = http.createServer(async function (
req: http.IncomingMessage,
res: http.ServerResponse,
) {
const decision = await aj.protect(req);
console.log("Arcjet decision", decision);
if (decision.isDenied()) {
res.writeHead(403, { "Content-Type": "application/json" });
res.end(JSON.stringify({ error: "Forbidden" }));
} else {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ message: "Hello world" }));
}
});
server.listen(8000);
We provide the source code for various packages in this repository, so you can find a specific one through the categories and descriptions below.
@arcjet/bun
: SDK for Bun.sh.@arcjet/deno
: SDK for Deno.@arcjet/nest
: SDK for NestJS.@arcjet/next
: SDK for Next.js.@arcjet/node
: SDK for Node.js.@arcjet/remix
: SDK for Remix.@arcjet/sveltekit
: SDK for SvelteKit.@arcjet/analyze
: Local analysis engine.@arcjet/headers
: Arcjet extension of the Headers
class.@arcjet/ip
: Utilities for finding the originating IP of a
request.@arcjet/redact
: Redact & unredact sensitive
information from strings.See the docs for details.
nosecone
: Protect your Response
with secure
headers.@nosecone/next
: Protect your Next.js
application with secure headers.@nosecone/sveltekit
: Protect your
SvelteKit application with secure headers.arcjet
: JS SDK core.@arcjet/body
: utilities for extracting the body from a
Node.js IncomingMessage.@arcjet/decorate
: Utilities for decorating responses
with information.@arcjet/duration
: Utilities for parsing duration
strings into seconds integers.@arcjet/env
: Environment detection for Arcjet variables.@arcjet/logger
: Lightweight logger which mirrors the
Pino structured logger interface.@arcjet/protocol
: JS interface into the Arcjet
protocol.@arcjet/runtime
: Runtime detection.@arcjet/sprintf
: Platform-independent replacement for
util.format
.@arcjet/transport
: Transport mechanisms for the
Arcjet protocol.@arcjet/eslint-config
: Custom eslint config for
our projects.@arcjet/redact-wasm
: Sensitive information
redaction detection engine.@arcjet/rollup-config
: Custom rollup config for
our projects.@arcjet/tsconfig
: Custom tsconfig for our projects.This repository follows the Arcjet Support Policy.
This repository follows the Arcjet Security Policy.
Licensed under the Apache License, Version 2.0.