---
source: https://iinventedlight.com/library/notes/fastapi-cors.md
title: "FastAPI CORS middleware"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (FastAPI docs); MIT (FastAPI source docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: FastAPI docs, CORS (Cross-Origin Resource Sharing); FastAPI source docs, cors.md. MIT (https://raw.githubusercontent.com/fastapi/fastapi/master/LICENSE). Copyright FastAPI contributors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: fastapi cors"
tags: [fastapi, cors, middleware, origins]
client: Librarian
sources:
  - id: S1
    title: "CORS (Cross-Origin Resource Sharing)"
    publisher: FastAPI docs
    url: https://fastapi.tiangolo.com/tutorial/cors/
    accessed: 2026-11-18
    license: "MIT"
  - id: S2
    title: "cors.md"
    publisher: FastAPI source docs
    url: https://raw.githubusercontent.com/fastapi/fastapi/master/docs/en/docs/tutorial/cors.md
    accessed: 2026-11-18
    license: "MIT"
---
# FastAPI CORS middleware
**Answer:** CORS, or Cross-Origin Resource Sharing, is the browser rule set for cross-origin HTTP requests. In FastAPI, configure it with `CORSMiddleware`. Create a list of allowed origins and add the middleware to the app.

## Examples

```python
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()
app.add_middleware(
    CORSMiddleware,
    allow_origins=["https://example.com"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)
```

## Rules

- Import `CORSMiddleware`. Create a list of allowed origins (as strings).
- A wildcard origin is incompatible with `allow_credentials=True` in browsers.

## See also

- [fastapi-dependencies](https://iinventedlight.com/library/notes/fastapi-dependencies/)

## Claims

- id: C1
  claim: CORS means Cross-Origin Resource Sharing.
  source: S1
  evidence: "Cross-Origin Resource Sharing"

- id: C2
  claim: Configure CORS with CORSMiddleware.
  source: S1
  evidence: "CORSMiddleware"

- id: C3
  claim: The source docs also document CORSMiddleware.
  source: S2
  evidence: "CORSMiddleware"

## Sources

- [S1] CORS (Cross-Origin Resource Sharing). FastAPI docs. https://fastapi.tiangolo.com/tutorial/cors/ . License: MIT. Accessed 2026-11-18.

- [S2] cors.md. FastAPI source docs. https://raw.githubusercontent.com/fastapi/fastapi/master/docs/en/docs/tutorial/cors.md . License: MIT. Accessed 2026-11-18.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: FastAPI docs, CORS (Cross-Origin Resource Sharing); FastAPI source docs, cors.md. MIT (https://raw.githubusercontent.com/fastapi/fastapi/master/LICENSE). Copyright FastAPI contributors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
