Configure CORS for Browser Clients
Allow trusted origins to call your API.
Configure CORS for Browser Clients is a free Flask Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Flask Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Browsers Block Calls
A browser refuses cross-origin requests by default for safety. This same-origin policy stops one site from quietly reading another.
What CORS Actually Is
CORS is a set of response headers that say which other origins may call your API. It opens the door on purpose.
An Origin Defined
An origin is the scheme, host, and port together. A different port or http versus https counts as a separate origin.
Meet Flask-CORS
You rarely write the headers by hand. The Flask-CORS extension adds the right ones for you on every response.
pip install Flask-CORSEnable It Globally
The simplest setup wraps the whole app. Calling CORS(app) allows every origin, which is fine while learning.
from flask_cors import CORS
CORS(app)Restrict to Trusted Origins
In real apps you name who may call you with origins. Anything not on the list is still blocked by the browser.
CORS(app, origins=["https://app.example.com"])Limit Which Routes
You can scope CORS to a path prefix with resources. Here only your API namespace is opened to outside callers.
CORS(app, resources={r"/api/*": {"origins": "*"}})The Key Header
Under the hood the magic is Access-Control-Allow-Origin. The browser reads it to decide whether to hand the response to your code.
Preflight Requests
For some calls the browser first sends an OPTIONS preflight to ask permission. Flask-CORS answers it automatically.
Allowing Credentials
To send cookies cross-origin you must set supports_credentials. Note that a wildcard origin is then no longer allowed.
CORS(app, supports_credentials=True)CORS Is Not Auth
Remember that CORS only guides browsers. It is not a security wall, so you still need real authentication on your API.
Quick Check
Choose where the CORS decision is enforced.
Recap
You saw why browsers block cross-origin calls, added Flask-CORS, restricted origins and routes, met preflight, and learned CORS is not auth. Well done!
Frequently asked questions
Is the “Configure CORS for Browser Clients” lesson free?
Yes — the full text of “Configure CORS for Browser Clients” is free to read here on the web, and the Flask Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Flask Academy course, upgrade to CoddyKit PRO.
What will I learn in “Configure CORS for Browser Clients”?
Allow trusted origins to call your API. You practise Flask Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Flask Academy?
No prior experience is required. Flask Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Configure CORS for Browser Clients” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Flask Academy lesson?
Yes. Every Flask Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Throttle Requests with Flask-Limiter
- Configure CORS for Browser Clients
- Security Headers and HTTPS
- Validate Input to Stop Injection