Course contentsShow
← Security
Lesson 875 of 3,05218. Web Security - CSRF and Request ForgeryFree lesson

CORS Request Types: Simple vs Preflight

Understanding simple requests versus preflighted requests and how browsers enforce CORS policies.

CORS Request Types: Simple vs Preflight

What you'll learn: You'll understand when browsers send a simple CORS request immediately versus when they send a preflight "permission check" first.

Not all cross-origin requests are created equal—browsers treat some as safe enough to send immediately, while others require a "pre-approval" step.

Simple Requests

A simple request goes directly to the server without any preliminary checks. Think of it like walking into a public library—no special permission needed. For a request to be "simple," it must meet ALL these criteria:

  • Uses only GET, HEAD, or POST methods
  • Contains only "safe" headers (Accept, Accept-Language, Content-Language, Content-Type)
  • If Content-Type is used, it must be application/x-www-form-urlencoded, multipart/form-data, or text/plain
  • No event listeners registered on any XMLHttpRequest upload object

These constraints mirror what a normal HTML form can do—which browsers already allow cross-origin.

Preflight Requests

A preflight request is a security checkpoint. Before sending the actual request, the browser first sends an OPTIONS request asking "Is this allowed?" Think of it like calling ahead to a restricted building to confirm your access.

Preflights trigger when requests:

  • Use methods like PUT, DELETE, or PATCH
  • Include custom headers (like X-API-Key or Authorization)
  • Send JSON with Content-Type: application/json

The server must respond with appropriate CORS headers (Access-Control-Allow-Methods, Access-Control-Allow-Headers) before the browser sends the real request.

Why This Matters

Browsers preflight "non-simple" requests to prevent legacy servers—built before CORS existed—from being tricked into dangerous operations. If a server doesn't explicitly approve these advanced requests, the browser blocks them entirely.

Key Takeaway: Simple requests (like basic forms) bypass preflight and go straight through, while complex requests (custom headers, JSON, non-GET/POST methods) require a preflight OPTIONS check to verify server permission before the actual request is sent.