-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This is a security update for the Same Origin Policy (SOP), and also a BREAKING CHANGE. closes GHSA-qxrj-hx23-xp82
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
'use strict'; | ||
|
||
const vary = require('vary'); | ||
|
||
/** | ||
* CORS middleware | ||
* | ||
* @param {Object} [options] | ||
* - {String|Function(ctx)} origin `Access-Control-Allow-Origin`, default is request Origin header | ||
* - {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` | ||
|
@@ -61,9 +60,11 @@ module.exports = function(options) { | |
let origin; | ||
if (typeof options.origin === 'function') { | ||
origin = await options.origin(ctx); | ||
if (!origin) return await next(); | ||
if (!origin) { | ||
return await next(); | ||
} | ||
} else { | ||
origin = options.origin || requestOrigin; | ||
origin = options.origin || '*'; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
julienw
Contributor
|
||
} | ||
|
||
let credentials; | ||
|
I'm puzzled because I don't see how this fixes the security advisory. Indeed
'*'
meansany origin
, so this is essentially the same behavior as before. Unless I'm missing something.I believe the advisory author would prefer that this behavior is explicit, that is as a user of the library I should specify
"*"
explicitely in theorigin
parameter.(I would myself be happy enough with just a stronger emphasis in the doc)