
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
Cross-Origin Resource Sharing(CORS) for koa
$ npm install @koa/cors --save
Enable cors with default options:
const Koa = require('koa');
const cors = require('@koa/cors');
const app = new Koa();
app.use(cors());
/**
* CORS middleware
*
* @param {Object} [options]
* - {String|Function(ctx)} origin `Access-Control-Allow-Origin`, default is '*'
* If `credentials` set and return `true, the `origin` default value will set to the request `Origin` header
* - {String|Array} allowMethods `Access-Control-Allow-Methods`, default is 'GET,HEAD,PUT,POST,DELETE,PATCH'
* - {String|Array} exposeHeaders `Access-Control-Expose-Headers`
* - {String|Array} allowHeaders `Access-Control-Allow-Headers`
* - {String|Number} maxAge `Access-Control-Max-Age` in seconds
* - {Boolean|Function(ctx)} credentials `Access-Control-Allow-Credentials`, default is false.
* - {Boolean} keepHeadersOnError Add set headers to `err.header` if an error is thrown
* - {Boolean} secureContext `Cross-Origin-Opener-Policy` & `Cross-Origin-Embedder-Policy` headers.', default is false
* - {Boolean} privateNetworkAccess handle `Access-Control-Request-Private-Network` request by return `Access-Control-Allow-Private-Network`, default to false
* @return {Function} cors middleware
* @api public
*/
The default origin is set to *, if you want to keep the 4.0 behavior, you can set the origin handler like this:
app.use(cors({
origin(ctx) {
return ctx.get('Origin') || '*';
},
}));
fengmk2 | dead-horse | omsmith | jonathanong | AlphaWong | cma-skedulo |
|---|---|---|---|---|---|
CleberRossi | erikfried | j-waaang | ltomes | lfreneda | matthewmueller |
PlasmaPower | swain | TyrealHu | xg-wang | lishengzxc | mcohen75 |
This project follows the git-contributor spec, auto updated at Sat Oct 08 2022 21:35:10 GMT+0800.
The 'cors' package is a popular middleware for enabling CORS in Express.js applications. It offers similar functionality to @koa/cors but is designed for use with Express.js instead of Koa.js.
The 'fastify-cors' package is a CORS plugin for Fastify, a fast and low-overhead web framework for Node.js. It provides similar CORS configuration options as @koa/cors but is tailored for Fastify applications.
The 'hapi-cors' package is a CORS plugin for Hapi.js, a rich framework for building applications and services. It offers similar CORS functionality to @koa/cors but is designed for use with Hapi.js.
FAQs
Cross-Origin Resource Sharing(CORS) for koa
The npm package @koa/cors receives a total of 440,554 weekly downloads. As such, @koa/cors popularity was classified as popular.
We found that @koa/cors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.