BeforeMerge

AI-native code review knowledge base. Structured rules that catch what linters miss.

Product

  • Features
  • Explore
  • Pricing
  • Docs
  • GitHub

Company

  • About
  • Blog
  • Contributors
  • Contributing

Legal

  • Privacy Policy
  • Terms of Service
  • MIT License

© 2026 BeforeMerge. Built by Peter Krzyzek

BeforeMerge
Features
Explore
PricingBlogContributorsInstall Guide
3Sign In
FeaturesExplore
RulesSkillsKnowledgePrompts
PricingBlogContributorsInstall Guide
Sign In

Explore

Browse 354 rules, 42 knowledge articles, and 28 prompt templates across security, performance, architecture, and quality.

Sort:
Previous1...111213...15Next

Automate these checks on every PR

BeforeMerge scans your pull requests against these rules automatically. Get actionable feedback before code ships to production.

Join WaitlistLearn More

354 rules

Validate File Uploads (Type, Size, Name, Content)

HIGH

Accepting file uploads without validating MIME type, size, extension, and filename sanitization enables code execution, storage abuse, and path traversal. [CWE-434 · A04:2021]

Securitynextjsfile-uploadNext.js

Understand CSRF Limitations in Server Actions

HIGH

Next.js Server Actions rely on Origin header checks, not CSRF tokens. Reverse proxies and misconfigured allowedOrigins can bypass this protection. [CWE-352 · A01:2021]

Securitynextjsauthentication

Restrict CORS to Specific Allowed Origins

HIGH

Setting Access-Control-Allow-Origin to wildcard or reflecting the request Origin lets any website make authenticated requests to your API. [CWE-942 · A05:2021]

Securitynextjscors

Never Pass Secrets or Sensitive Data to Client Components

CRITICAL

Props passed to Client Components are visible in the browser. Never pass API keys, tokens, or full database records to client code. [CWE-200 · A01:2021]

Securitynextjsdata-exposure

Prevent Cache Poisoning in ISR and SSR Routes

HIGH

Misconfigured caching of Next.js ISR/SSR responses allows attackers to poison cached pages with blank or malicious content, causing DoS for all users. [CWE-444 · A05:2021]

Securitynextjsisr

Validate External Data at System Boundaries

MEDIUM

TypeScript types vanish at runtime. Validate external data at system boundaries with Zod to prevent crashes from unexpected shapes. [CWE-20]

QualitynextjsValidation

Ban any at Trust Boundaries — Use unknown with Validation

HIGH

Using 'any' or 'as any' at API boundaries, form handlers, and external data silently disables TypeScript safety, causing runtime crashes from unexpected data. [CWE-20]

Qualityanynextjs

Never Use Type Assertions on External Data — Validate Instead

MEDIUM

Casting API responses, form data, or URL params with 'as Type' bypasses TypeScript guarantees. When the shape doesn't match, crashes happen far from the boundary. [CWE-20]

QualitynextjsValidation

Never Hardcode Secrets — Use Environment Variables Properly

HIGH

Hardcoded secrets persist in Git history forever. Use environment variables and never prefix secrets with NEXT_PUBLIC_. [CWE-798 · A07:2021]

Qualitynextjsconfiguration

Always Return Cleanup Functions from useEffect

HIGH

useEffect hooks that set up subscriptions, timers, or event listeners without cleanup cause memory leaks, stale state updates, and race conditions.

Performanceuseeffectnextjs

Prevent Unnecessary Re-renders from Unstable References

HIGH

Inline objects, arrays, and functions as props create new references every render, defeating React.memo and causing cascading re-renders across the tree.

Performanceusecallbacknextjs

Avoid Stale Closure Bugs in Hooks and Callbacks

MEDIUM

Event handlers and effects that capture state in closures can reference outdated values, causing silent data corruption and missed updates.

Performanceuseeffectnextjs

Prefer Server Components — Only Add 'use client' When Necessary

HIGH

Adding 'use client' unnecessarily ships component JS to the browser. Only use it when you need hooks, event handlers, or browser APIs.

Performancenextjsbundle-size

Parallelize Independent Async Operations

CRITICAL

Sequential await calls on independent operations create request waterfalls. Use Promise.all or Suspense boundaries to parallelize.

Performancenextjsasync

Eliminate N+1 Database Queries

CRITICAL

Fetching related data inside loops creates N+1 queries that scale linearly with data size. Use eager loading or batch queries instead. [CWE-400]

Performancedrizzlenextjs

Use Stable, Unique Keys for List Items (Never Index)

MEDIUM

Using array indices as key props causes incorrect state preservation, UI corruption, and degraded performance when lists are reordered or filtered.

PerformancenextjsReact

Use next/image Instead of Raw img Tags

HIGH

Raw <img> tags skip automatic optimization, lazy loading, and responsive sizing. next/image provides WebP/AVIF conversion, blur placeholders, and CLS prevention.

PerformanceImagesnextjs

Use next/font Instead of External Font Loading

MEDIUM

External font loading from Google Fonts or CDNs causes layout shift and render-blocking requests. next/font self-hosts fonts with zero layout shift.

Performancenextjsfonts

Use Dynamic Imports for Heavy Client Components

HIGH

Large client libraries loaded synchronously block the initial page load. Use next/dynamic or React.lazy to code-split and load them on demand.

Performancenextjsdynamic-imports

Avoid Barrel File Imports in Client Components

HIGH

Barrel file imports in Client Components force bundlers to load entire libraries. Use direct imports or Next.js optimizePackageImports.

Performancenextjsimports

Implement loading.tsx and error.tsx at Every Route Segment

MEDIUM

Missing loading.tsx causes full-page spinners instead of granular streaming. Missing error.tsx lets errors crash parent layouts instead of being contained.

Architecturenextjs

Break Up God Components Into Focused, Composable Units

MEDIUM

Components handling data fetching, business logic, state, and rendering are hard to test and maintain. Decompose by responsibility.

Architecturesingle-responsibility

Add Error Boundaries Around Unreliable Content

MEDIUM

Without error boundaries, a single component failure crashes the entire page. Use error.tsx and granular ErrorBoundary wrappers.

Architecturenextjs

Keep API Route Handlers Thin — Delegate to Services

CRITICAL

API routes with business logic are hard to test, audit, and secure. Keep route handlers under 100 lines by delegating to service classes. [CWE-1064]

Securitysingle-responsibilitythin-controllers
Next.js
Next.js
Next.js
Next.js
Next.js
Next.js
Next.js
Next.js
Next.js
Next.js
Next.js
Next.js
Next.js
Next.js
Next.js
Next.js
Next.js
Next.js
Next.js
suspense
Next.js
components
Next.js
resilience
Next.js
Architecture