Sanic-Cors
A Sanic extension adding a decorator for CORS support. Based on flask-cors by Cory Dolphin.
What it is and what it does
Sanic-CORS is a Sanic web framework extension that handles Cross-Origin Resource Sharing (CORS) headers and preflight requests, allowing your Sanic application to safely serve cross-origin AJAX requests. It is based on flask-cors and provides both a global initialization approach and per-route decorator patterns for fine-grained control over which origins, methods, and headers are allowed.
The extension operates with a permissive default philosophy: when enabled globally, it allows CORS for all origins and methods on all routes unless you explicitly configure restrictions. It includes an automatic_options feature to handle OPTIONS preflight responses without manual route configuration. The package depends on sanic and packaging, and supports Python 3.7 through 3.10. However, the project has been abandoned since early 2023, with the last release in October 2022, and carries two known security vulnerabilities.
Use it for:
- Enable CORS globally on a Sanic API to allow browser-based clients from any origin to make cross-origin requests.
- Configure CORS selectively for specific API routes using the @cross_origin decorator to restrict which origins can access sensitive endpoints.
- Set up resource-level CORS policies by mapping URL patterns to specific allowed origins, methods, and headers in the resources parameter.
- Automatically handle CORS preflight OPTIONS requests without manually implementing OPTIONS handlers on each route.
- Integrate CORS support into a Sanic application managed by Sanic-Ext using the plugin system.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Sanic-CORS is a Sanic extension that adds Cross-Origin Resource Sharing (CORS) support to Sanic web applications, enabling cross-origin AJAX requests with configurable per-route or global policies.
No. While Sanic-CORS provides straightforward CORS support with low install friction and permissive licensing, the project is abandoned (last commit January 2023) and carries two known security vulnerabilities. For new projects, consider alternatives or implement CORS handling directly. For existing projects already using it, evaluate whether upgrading to a maintained solution is feasible.
Install
sanic-cors on PyPI
pip
pip install sanic-corsuv
uv add sanic-corspoetry
poetry add sanic-corsInstalling Sanic-Cors
Before you install
Installation is straightforward with low friction. The package depends only on sanic and packaging. However, maintenance is a concern: the last release was October 2022 and the repository shows no commits since January 2023, indicating the project is abandoned despite the repository not being formally archived.
License in practice
MIT license is permissive and poses no restrictions on use, modification, or distribution in commercial or private projects.
Quickstart
pip install sanic-cors
from sanic import Sanic
from sanic.response import text
from sanic_cors import CORS
app = Sanic(__name__)
CORS(app)
@app.route("/", methods=['GET', 'OPTIONS'])
def hello_world(request):
return text("Hello, cross-origin-world!")
Sanic-CORS requires routes to explicitly include 'OPTIONS' in the methods list to handle CORS preflight requests, unless automatic_options is enabled.
Verify before relying
- Whether the two known vulnerabilities (GHSA-94jw-hqvj-vw74, PYSEC-2026-3539) have been patched or remain unresolved in version 2.2.0.
- Compatibility status with current Sanic versions beyond the notices provided for v21.9, v21.12, and v22.9.
- Whether the package will receive security updates or bug fixes despite abandonment status.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — sanic, packaging |
| Maintenance | abandoned — 1,407 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 311,128/month — #7,740 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | 2 — GHSA-94jw-hqvj-vw74, PYSEC-2026-3539 |
Evidence: Sanic_Cors-2.2.0-py2.py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
flask-corsFlask-CORS handles Cross-Origin Resource…
permissive · top 1,000 on PyPI
sanic-extSanic Extensions adds OpenAPI documentation,…
permissive · top 15,000 on PyPI
invenio-restInvenio-REST provides Flask-based REST API…
permissive · top 15,000 on PyPI
quart-corsQuart-CORS adds Cross-Origin Resource Sharing…
permissive · top 15,000 on PyPI
django-cors-headersAdds Cross-Origin Resource Sharing (CORS)…
permissive · top 1,000 on PyPI
aiohttp-corsAdds Cross-Origin Resource Sharing (CORS)…
permissive · top 5,000 on PyPI
fastapi-corsConfigures CORS settings for FastAPI…
permissive · top 15,000 on PyPI
sanic-routingSanic-routing is a low-level AST-style router…
permissive · top 5,000 on PyPI
cherrypy-corsAdds Cross-Origin Resource Sharing (CORS)…
permissive · top 15,000 on PyPI
sanicSanic is an async Python web framework and…
permissive · top 5,000 on PyPI