Cross-origin requests are allowed from every origin

tx0/python:cors-any-originrecommendedwarningsecurity, cwe-942

What it finds

Allowing every origin lets any web site read the responses of this one in its visitors' browsers, with their cookies if credentials are allowed too. Reported are CORS(app) from flask_cors without origins, CORSMiddleware and CORS given "*" as allow_origins or origins, the Django settings CORS_ALLOW_ALL_ORIGINS = True and CORS_ORIGIN_ALLOW_ALL = True, and a header Access-Control-Allow-Origin set to "*".

From the rule's source, cors_any_origin.rs.

Example from the rule's tests
from flask_cors import CORSfrom fastapi.middleware.cors import CORSMiddleware CORS(app)tx0 reports: CORS(app) without origins lets every origin read the responsesCORS(app, origins=["https://example.com"])app.add_middleware(CORSMiddleware, allow_origins=["*"])tx0 reports: every origin may read the responsesCORS_ALLOW_ALL_ORIGINS = Truetx0 reports: this setting lets every origin read the responsesresponse.headers["Access-Control-Allow-Origin"] = "*"tx0 reports: this header lets every origin read the response
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:cors-any-origin" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:cors-any-origin] reason="..."

tx0 explain tx0/python:cors-any-origin shows the same in the terminal. Found a false positive? Report it.