CORS — Security · NestJS

A browser will not let a page on one site read this API's answers unless the API says so: cross-origin resource sharing is that permission, granted origin by origin, method by method, in headers, with a preflight request the browser sends first.

What you will learn

Read the theory for CORS

All Security lessons

All NestJS courses

loading types…

What you'll learn

  • Explain the same-origin policy and what CORS changes: a browser rule, lifted by the server's headers, that never stops a non-browser client
  • Enable CORS on a Nest app for a list of origins, with the methods, headers, credentials and preflight cache the front end needs
  • Read a preflight request and its answer, and tell it from the actual request
  • Say why a refused origin still gets a 200 body and no Access-Control headers, and why '*' and credentials cannot be combined