papertrail/middleware.ts
caelum0x 695a365ae4 feat: PaperTrail — enterprise evidence-verification platform
Multi-tenant platform (182 pages, 228 API routes, ~30 modules) built on a
deterministic verification core: clinical-trial claims checked against
ClinicalTrials.gov registered results and raw event counts (ARR/NNT/RR+CI
recomputed in code, oracle-tested), code-enforced exact-span grounding, and
multi-source cross-verification. Auth/RBAC/multi-tenancy, document processing
at scale (unpdf + Docling), agentic workflows, Claude Science connector,
compliance/audit, billing, public API, and more.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 07:21:22 +03:00

30 lines
1.0 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
const SESSION_COOKIE = "pt_session";
// Two concerns, one middleware:
// 1. /console/* is protected — redirect to /login when there's no session cookie.
// 2. Every response gets baseline security headers. Rate limiting itself lives
// in the /api/verify route handler (needs per-route config, not global).
export function middleware(req: NextRequest) {
const { pathname } = req.nextUrl;
if (pathname === "/console" || pathname.startsWith("/console/")) {
const hasSession = Boolean(req.cookies.get(SESSION_COOKIE)?.value);
if (!hasSession) {
const loginUrl = new URL("/login", req.url);
return NextResponse.redirect(loginUrl);
}
}
const res = NextResponse.next();
res.headers.set("X-Content-Type-Options", "nosniff");
res.headers.set("X-Frame-Options", "DENY");
res.headers.set("Referrer-Policy", "strict-origin-when-cross-origin");
return res;
}
export const config = {
matcher: ["/api/:path*", "/console/:path*"],
};