-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add config for Access-Control-Allow-Origin #7
Conversation
kcors 默认 `Access-Control-Allow-Origin: '*'`,取消这一默认项的确有安全方面的考虑,但是完全和 egg-security 的 `domainWhiteList` 绑定,不一定是最好的。 而且 egg-cors 虽然与安全有关,但毕竟是一个独立插件,有自己的配置项,如果必须同时依赖 egg-security 的设置,在设计上也值得商榷。 不作为默认,但允许用户自定义,也许更好,兼顾安全与灵活。
@brickyang, thanks for your PR! By analyzing the history of the files in this pull request, we identified @fengmk2 to be a potential reviewer. |
Codecov Report
@@ Coverage Diff @@
## master #7 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 3 3
Lines 9 9
=====================================
Hits 9 9
Continue to review full report at Codecov.
|
egg-security 是 egg 的核心能力之一,egg-cors 这些外围插件,依赖它问题不大吧。 而且这个插件也就几行代码,如果真的需要的话,其实都可以直接在应用里面写个 middleware 引入 kcors 即可,不需要这个插件了。 |
@atian25 是的,你说的这两个问题我都考虑过。 我认为现在的做法不是最优的原因有这样几个: 1. 配置不一致 2. 一个插件,两处配置 3. domainWhiteList 缺少扩展性 所以我认为允许
而且这个方案对现在的一切都没有影响,origins 默认仍然使用 自己引入 kcors 也是一个选择。但我认为,「origin 应该有扩展性」并没有超出 egg-cors 的范围(而是应有的),所以我们应该去改进它(而不是另起炉灶)。 个人浅见供参考 :) |
@jtyjty99999 你的看法?cc @eggjs/core |
同意 @brickyang ,security 的作为默认值即可 |
@brickyang 加个测试用例吧 |
OK |
请忽略 package-lock.json |
commit log 请改成英文的。 |
package.json
Outdated
@@ -20,17 +20,17 @@ | |||
"egg-plugin" | |||
], | |||
"dependencies": { | |||
"kcors": "^1.3.2" | |||
"kcors": "^2.2.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/koajs/cors/blob/master/History.md#200--2016-02-20 kcors 是基于koa@2的,egg 目前还是基于 koa@1 的,目前还不能升级 kcors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
抱歉,已改。
@brickyang 请将 commit log 改成英文版本 |
我们自己 squash 改也行吧,下次 PR 注意就好了。 |
没事的,多搞几次就熟悉了,没啥的。 可以看下 https://eggjs.org/zh-cn/contributing.html 我当年的第一个 PR 更惨,哈哈 |
都忘了这个 PR 了,先合了,等 #8 一起发版本。 |
@brickyang 1.2.0 |
feat: add config for Access-Control-Allow-Origin
Now you can use
config.cors.origin
to setAccess-Control-Allow-Origin
response header.If
origin
is set, the plugin will ignore thesecurity.domainWhiteList
. Otherwise, domainWhiteList will do its job.Checklist
npm test
passesAffected core subsystem(s)
none