SKY-D247 · Security in code
CORS middleware open to every origin
The cors package for Express and similar Node servers decides which other websites may call your API from a browser and read the answer. SKY-D247 reports cors({ origin: "*" }) and cors({ origin: true }), which allow every website.
- Languages
- TypeScript/JavaScript
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
- Catalog name
- CORS wildcard origin
Why it matters
Any page a user opens can then read your API's responses from their browser. With origin: true and credentials: true, the browser also sends the user's cookies, so another site can read their account data.
What Skylos flags
import cors from "cors";import express from "express"; const app = express(); app.use(cors({ origin: "*", methods: ["GET", "POST"] }));What Skylos leaves alone
import cors from "cors";import express from "express"; const app = express();const allowed = new Set(["https://app.example.com", "https://admin.example.com"]); app.use( cors({ origin: (origin, callback) => callback(null, !origin || allowed.has(origin)), credentials: true, }),);Why Skylos leaves it alone
origin is a function that accepts only the two listed sites (and requests with no Origin, such as server-to-server calls). The rule reports only the literal values "*" and true.
How Skylos decides
- Runs with
--dangeron TypeScript and JavaScript files. Finds calls to a function named exactlycorswhose first argument is an object literal. - Reports MEDIUM when that object has a property written
originwhose value, with quotes removed, is*ortrue. - Nothing else is read:
cors()with no options (which thecorspackage also treats as "every origin"), options held in a variable, a quoted"origin"key,origin: ["*"]and anAccess-Control-Allow-Originheader set by hand are not reported. Whether credentials are enabled does not change the result. Python CORS settings are SKY-D231.
How to fix it
List the sites that may call the API. Use an array of origins, or a function that checks the request's origin against a fixed set. Enable credentials only with such a list.
import cors from "cors";import express from "express"; const app = express(); Removed: app.use(cors({ origin: "*", methods: ["GET", "POST"] }));Added: app.use(Added: cors({Added: origin: ["https://app.example.com", "https://admin.example.com"],Added: methods: ["GET", "POST"],Added: }),Added: );When it can be wrong
- A public API that is meant to be read by every site, such as open data or a status endpoint with no cookies, is still reported.
app.use(cors())with no options allows every origin but is not reported, nor is a configuration object built elsewhere and passed in as a variable.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Mark the line of the
cors(…)call and say why every origin is acceptable.TypeScript app.use(cors({ origin: "*" })); // skylos: ignore[SKY-D247] public API[tool.skylos] ignore = ["SKY-D247"]turns the rule off for the whole project.