Closed codefine closed 6 years ago
Merging #26 into master will increase coverage by
0.02%
. The diff coverage is100%
.
@@ Coverage Diff @@
## master #26 +/- ##
=========================================
+ Coverage 95.88% 95.9% +0.02%
=========================================
Files 26 26
Lines 437 440 +3
=========================================
+ Hits 419 422 +3
Misses 18 18
Impacted Files | Coverage Δ | |
---|---|---|
lib/utils.js | 77.08% <100%> (+1.52%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update e341fc3...bea0ccf. Read the comment docs.
use wildcard library like https://github.com/sindresorhus/matcher
@dead-horse 源文件使用endsWith来判断,这个模块需要植入到源文件中吧?
// utils.js
const matcher = require('matcher');
exports.isSafeDomain = function isSafeDomain(domain, domain_white_list) {
// add prefix `.`, because all domains in white list are start with `.`
const hostname = '.' + domain;
return domain_white_list.some(function(rule) {
// return matcher.isMatch(hostname, rule); // 直接使用的话会在'should return true when domain is save'用例的res.text.should.equal('true');返回false
if (/\*/g.test(rule)) {
return matcher.isMatch(hostname, rule);
}
return hostname.endsWith(rule);
});
};
// utils.test.js
const domainWhiteList = [ '111.222.1.*' ];
utils.isSafeDomain('111.222.1.3', domainWhiteList).should.equal(true); // false
我添加的简单逻辑已经可以满足需求了,而且matcher的!功能和白名单语义互斥,也用不上。
我们这个项目前后端分离,开发时需要将所有局域网ip添加至白名单,需要设置成192.168.1.*
;
而发布时则需要添加所有二级域名至白名单,需要设置成*.somedomain.com
;
也可能是我理解的不够,无需修改源码就能实现,如果是这样的话,请死马大大给点思路。多谢🙏。
ping @jtyjty99999
判断一下如果包含 wildcard 字符就用 wildcard 的库来处理,否则就沿用原来的 endsWith 好了
@dead-horse:This has been merged and fixed. So close this :)
@Maledong this feature is landed ? which PR?
Add wildcard character(
*
) rule todomainWhiteList
.The
config.security.domainWhileList
can node like blow:It helps greatly with client-server-separation development when using egg.