Audit API Route Handlers for Auth and Permission Leaks

Get a structured security audit of your API route handlers that evaluates tenant isolation, role-based access control, and input validation risks.

Agent prompt for Claude

Prompt

Prompt
Act as a Senior Security Engineer. I will paste my API route handler code. Audit the code for auth and permission vulnerabilities. Follow these rules: 1. Evaluate every endpoint for potential cross-tenant data leaks. 2. Verify that RBAC checks occur before data fetching. 3. Check for parameter tampering risks by validating ID ownership against the session user. 4. Do not suggest generic best practices; focus on concrete code flaws. This is not legal or security compliance advice; consult a professional security auditor for production systems. Output format: A table with columns: Endpoint Path, Risk Category, Severity, and Remediation. Followed by a list of high-priority security action items.

Example output

Example for: an Express.js profile management controller.

Endpoint PathRisk CategorySeverityRemediation
GET /users/:idTenant IsolationCriticalCheck if req.user.tenantId matches user.tenantId from the database before returning data.
PATCH /users/:idParameter TamperingHighValidate that the ID in the URL matches the session user ID or verify admin scope.
POST /users/:id/settingsRBAC CheckMediumAdd a middleware to verify the user has the 'owner' or 'admin' role for this specific record.
Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Forces a tabular format for quick identification of security gaps.
  • Specifically targets high-risk areas like cross-tenant leaks and parameter tampering.
  • Requires actionable remediation steps rather than vague advice.

Copy your API route handler file or a selection of endpoints and paste it after this prompt. Works best in Claude or Claude Code when analyzing Express, FastAPI, or Hapi routes.

Common edits

  • Add a specific framework name like 'FastAPI' or 'Next.js' to the prompt for more accurate syntax analysis.
  • Expand the table to include a column for 'Current Code snippet' if you need the model to point to specific lines.

Reuse it: Use in a workflowAdapt in the builder

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

More in Claude Code

Audit a TypeScript API Route for Race Conditions, Auth, and N+1 Bugs

Get a severity-ranked security and performance audit of your TypeScript API route with exact line numbers, concrete exploit or failure scenarios, and minimal targeted fix diffs.

Audit a Pull Request Diff for Breaking API Changes

Separates wire-breaking schema, status code, and migration changes from safe additions, returning a consumer impact table and deprecation plan.

Audit Cursor Rules Files for Conflicts and Context Bloat

Get a line-by-line audit of your .cursor/rules files that flags overlapping globs, contradictory instructions, and token waste, plus a consolidation diff.

Compare Three Feature Architectures Against Module Boundaries

Get a scored trade-off matrix comparing three feature architectures by file touchpoints, coupling risks, and rollback cost before running Cursor Composer.

Generate OpenAPI 3.1 Specs and JSDoc from Route Handlers

Turns pasted Express, Fastify, or Next.js route handlers into valid OpenAPI 3.1 YAML specs, typed JSDoc blocks, and a list of undocumented error edge cases.

AI Coding AgentsClaude Code

Audit AI Code Diffs for Performance Regressions

This prompt scans code changes for silent performance killers like N+1 queries, unindexed filters, and memory leaks before you merge them.