AbuseGraph + Express
Express middleware calls the HTTPS API before issuing a signup or login session.
Quick path
- Set
ABUSEGRAPH_SECRET_KEYandABUSEGRAPH_SITEin env. - Copy a test key from the console; no package installation is required for the HTTPS API path.
- Add middleware on register/login routes that calls
scoreAuthbefore issuing a session.
Keys
| Key | Env | Use |
|---|---|---|
| Secret | ABUSEGRAPH_SECRET_KEY (sk_test_… / sk_live_…) | Server /api/v1/check |
| Publishable | NEXT_PUBLIC_ABUSEGRAPH_PUBLISHABLE_KEY (pk_test_…) | Browser SDK |
| Site | ABUSEGRAPH_SITE | DNS-verified domain |
Free includes 1,000 live API checks / month after DNS verify. Test keys never bill.
Env
ABUSEGRAPH_SITE=yourdomain.com
ABUSEGRAPH_CHECK_URL=https://abusegraph.com/api/v1/check
ABUSEGRAPH_SECRET_KEY=sk_test_…
ABUSEGRAPH_SECRET_KEY_TEST=sk_test_…
NEXT_PUBLIC_ABUSEGRAPH_PUBLISHABLE_KEY=pk_test_…Use sk_live_… in production after DNS verify.
Server check
Call the HTTPS API from your server. Keep ABUSEGRAPH_SECRET_KEY in server-only environment configuration. Events: signup | login | password_reset | email_change; sessionId is optional.
const API = "https://abusegraph.com/api/v1/check";
export async function scoreAuth(input: Record<string, unknown>) {
const site = process.env.ABUSEGRAPH_SITE!;
const response = await fetch(API, {
method: "POST",
headers: {
"content-type": "application/json",
"x-api-key": process.env.ABUSEGRAPH_SECRET_KEY!,
"x-abusegraph-site": site,
},
body: JSON.stringify({
...input,
event: typeof input.event === "string" ? input.event : "signup",
site,
}),
});
if (!response.ok) throw new Error(`AbuseGraph check failed: ${response.status}`);
return response.json();
}Run this before creating an account or issuing a session. Handle block and challenge according to your policy; 402 means the live monthly allowance is exhausted.
Browser signals (recommended)
Load the browser SDK from the AbuseGraph CDN before your signup/login code. The publishable key is safe to expose; send the resulting body to your own backend, which makes the authoritative check with its server-held secret key.
<script src="https://abusegraph.com/sdk/abusegraph.min.js"></script>
<script>
const sdk = AbuseGraph.init({ publicKey: "pk_test_…" });
async function collectForAuth(email, event = "signup") {
const collected = await sdk.collect();
const evaluated = await sdk.evaluate(collected, { email });
return sdk.toCheckBody(collected, {
email,
event,
verdictToken: evaluated.verdictToken?.token,
});
}
</script>POST the returned JSON to your own endpoint. Never treat the browser result as the authoritative decision or put an sk_ key in browser code.
Express middleware
import type { Request, Response, NextFunction } from "express"
export function abusegraphGuard(event: "signup" | "login") {
return async (req: Request, res: Response, next: NextFunction) => {
const email = req.body?.email
if (!email) return next()
const { password, ...browserFields } = req.body
const result = await scoreAuth({
...browserFields,
email,
event,
ip: req.ip,
})
if (result.verdict === "block") {
return res.status(403).json({ error: "blocked", ...result })
}
if (result.verdict === "challenge") {
// require step-up before session create
}
res.locals.abusegraph = result
next()
}
}
app.post("/register", abusegraphGuard("signup"), createUserHandler)
app.post("/login", abusegraphGuard("login"), loginHandler)Lifecycle events
- login —
abusegraphGuard("login")before session create. - password_reset — middleware or route handler with
event: "password_reset". - email_change — call check before applying the email update with
event: "email_change".
Platform
Lists, rules, and linked accounts apply on every check — configure in the console. Optional session: POST /api/v1/session. Native apps: iOS, Android, React Native.
Verify
POST to /register with sk_test_…, confirm Activity shows the check, and blocked emails get 403.