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.
Agent prompt for Claude and Gemini
You get: Findings Summary Table with columns and detailed Findings
Prompt
mkdir -p .agents/skills/audit-a-typescript-api-route-for-race-conditions-auth-and-n-1-bu && curl -sL "https://prompts-gpt.com/prompts/audit-a-typescript-api-route-for-race-conditions-auth-and-n-1-bugs/raw" -o .agents/skills/audit-a-typescript-api-route-for-race-conditions-auth-and-n-1-bu/SKILL.mdAct as a staff backend security and performance engineer reviewing a production TypeScript API route.
Audit the code I paste right after this prompt for three failure classes: race conditions (check-then-act bugs, missing transactions, lost updates), authorization bypasses (IDOR, missing tenant scoping, role escalation), and N+1 database queries.
Follow these rules:
- Cite the exact line number or symbol name for every finding and skip generic style or formatting feedback.
- Write one concrete exploit or concurrent failure scenario for each finding, showing the exact request sequence or query count.
- Keep every fix diff minimal and targeted to the root cause without refactoring unrelated code.
- Rank findings from Critical to Low and omit any category that has no real issue in the pasted code.
- Include one concrete verification check (a test case or query-count assertion) for every Critical or High finding.
Output format:
1. Findings Summary Table with columns: Severity, Category, Line or Symbol, and Issue.
2. Detailed Findings: numbered sections matching the table, each with Root Cause, Failure or Exploit Scenario, Minimal Fix Diff, and Verification Check.
3. Assumptions and Missing Context: list any unseen middleware, database constraints, or isolation levels that could change the severity.Example output
Tips and common edits
Why this works
- Constrains the audit to three high-impact backend failure classes so the model skips low-value linting feedback.
- Requires concrete exploit or concurrent request sequences, which forces the model to prove a bug is real before reporting it.
- Pairs every Critical or High finding with a verification test so you can confirm the fix in CI.
Use in Cursor, Claude, or Gemini before merging billing, auth, or high-traffic API routes. Paste the route handler plus any auth middleware or repository helpers it calls so the audit can trace tenant checks and database queries.
Common edits
- Add your ORM name (Prisma, Drizzle, or TypeORM) to the first line so fix diffs match your exact query API.
- Include rate-limiting or input-validation checks in the second paragraph when auditing public unauthenticated endpoints.
Reuse it: Use in a workflowAdapt in the builder
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
More like this
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.
Audit Git Diffs for Race Conditions and Shared Mutable State
Reviews code diffs for silent concurrency bugs, mapping concurrent execution timelines and providing exact thread-safe mitigation fixes.
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.
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.
Reconcile OpenAPI Schema Drift with Backend Logic
Get a three-column alignment matrix that identifies discrepancies between your OpenAPI spec, TypeScript client types, and actual backend request validation logic.
- Audit PR Git Diffs for Scope Creep and Churn
- Review AI Pull Requests for Phantom Imports and Bloat
- Security Review of a Code Snippet: Ranked Findings With Exploit Path and Fix
- Pull Request Review with Merge Recommendation
- Audit Front-End Code Against Web Interface Guidelines
- Supabase RLS and Postgres Migration Review: Indexes, Locks