Require API Auth, Validation, and Tenant Scoping

Flags API endpoints that skip auth, trust client-supplied tenant or account IDs, accept unvalidated request bodies, or leak internal errors.

What it flags

Flaggedapp/api/projects/route.ts
import { db } from '@/lib/db';

export async function POST(req: Request) {
  const body = await req.json();

  // No session check, no validation, and the client picks the organization
  const project = await db.project.create({
    data: {
      name: body.name,
      organizationId: body.organizationId,
    },
  });

  return Response.json(project);
}
Passesapp/api/projects/route.ts
import { z } from 'zod';

import { getSession } from '@/lib/auth';
import { db } from '@/lib/db';

const CreateProject = z.object({
  name: z.string().trim().min(1).max(100),
});

export async function POST(req: Request) {
  const session = await getSession();
  if (!session) {
    return Response.json({ error: 'Unauthorized' }, { status: 401 });
  }

  const parsed = CreateProject.safeParse(await req.json().catch(() => null));
  if (!parsed.success) {
    return Response.json({ error: 'Invalid request body' }, { status: 400 });
  }

  const project = await db.project.create({
    data: { name: parsed.data.name, organizationId: session.organizationId },
  });
  return Response.json(project, { status: 201 });
}

Why it matters

Cross-tenant data leaks usually come from a handler that reads an organization or account ID from the request and queries by it without checking that the caller belongs to it. The handler works in every happy-path test because the tester uses their own IDs. Missing validation has the same shape: the endpoint accepts whatever JSON arrives, and malformed or malicious input reaches the database or a downstream service.

Agent instructions

cubic checks every pull request against these instructions. Paste them into AGENTS.md or Cursor rules and your AI coding tool follows them while it writes code.

AGENTS.md

Add this section to AGENTS.md at the repository root. Codex, Cursor, and other AI coding tools read it.

## Require API Auth, Validation, and Tenant Scoping

Review API handlers and controller endpoints for missing authentication, authorization, tenant scoping, and request validation.

Flag new or modified endpoints that:
- Accept request bodies without runtime validation, such as Zod schemas, DTOs, or framework-native validators.
- Trust user-supplied identifiers for tenant, organization, or account access instead of deriving access from the authenticated session.
- Return sensitive internal errors or use inconsistent HTTP status codes for 400, 401, 403, 404, and 500 cases.
- Mix reads and writes in a way that makes side effects hard to reason about.
- Add public or high-volume endpoints without rate limiting or abuse controls.

Checks every changed file.

Related agents

Included in the Next.js, TypeScript, Node.js, Python, Django, Ruby on Rails, Go, and Spring Boot code review standards.

Run this agent on every pull request

cubic reviews every pull request against the agents you turn on and comments on the lines that break them.

Catch this in your code