Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuy-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
1
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Plain Diff
Browse Files
Authored by
yyq
7 years ago
Commit
f98f28069aec1049e5b4b01c289d04dd1fc88ae8
2 parents
8c66934b
8c776188
Merge branch 'feature/whiteIp' into release/0627
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
27 deletions
apps/3party/controllers/sitemap.js
doraemon/middleware/error-handler.js
doraemon/middleware/limiter/index.js
doraemon/middleware/limiter/rules/ip-white-list.js
apps/3party/controllers/sitemap.js
View file @
f98f280
...
...
@@ -7,7 +7,7 @@ const sm = require('sitemap');
const
staticUrls
=
require
(
'../../../config/staticUrls'
);
const
headerModel
=
require
(
'../../../doraemon/models/header'
);
const
siteMapService
=
require
(
'../models/site-map-service'
);
const
cache
=
global
.
yoho
.
cache
;
const
cache
=
global
.
yoho
.
cache
.
master
;
const
getStaticUrls
=
(
currentStatics
)
=>
{
let
urls
=
[];
...
...
doraemon/middleware/error-handler.js
View file @
f98f280
...
...
@@ -11,6 +11,7 @@ const config = global.yoho.config;
const
hostname
=
require
(
'os'
).
hostname
();
const
routeEncode
=
require
(
'./route-encode'
);
const
pathWhiteList
=
require
(
'./limiter/rules/path-white-list'
);
const
ipWhiteList
=
require
(
'./limiter/rules/ip-white-list'
);
const
_
=
require
(
'lodash'
);
const
limiterIpTime
=
3600
;
...
...
@@ -104,7 +105,7 @@ exports.serverError = () => {
if
(
err
.
code
===
9999991
||
err
.
code
===
9999992
)
{
let
remoteIp
=
req
.
yoho
.
clientIp
;
if
(
!
_
.
includes
(
pathWhiteList
(),
req
.
path
))
{
if
(
!
_
.
includes
(
pathWhiteList
(),
req
.
path
)
&&
!
(
await
ipWhiteList
(
remoteIp
))
)
{
const
isHuman
=
await
cache
.
getAsync
(
`
$
{
config
.
app
}:
limiter
:
api
:
ishuman
:
$
{
remoteIp
}
`
);
if
(
!
isHuman
)
{
...
...
doraemon/middleware/limiter/index.js
View file @
f98f280
...
...
@@ -15,25 +15,6 @@ const captchaPolicy = require('./policies/captcha');
// const reporterPolicy = require('./policies/reporter');
const
IP_WHITE_LIST
=
[
'106.38.38.146'
,
// 北京办公区域
'106.38.38.147'
,
// 北京办公区域
'106.39.86.227'
,
// 北京办公区域
'218.94.75.58'
,
// 南京办公区域
'218.94.75.50'
,
// 南京办公区域
'218.94.77.166'
,
// 南京办公区域
// '222.73.196.18', // B站合作方单击次数快加白名单
'123.206.73.107'
,
// 腾讯云出口IP
'139.199.35.21'
,
// 腾讯云出口IP
'139.199.29.44'
,
// 腾讯云出口IP
'123.206.21.19'
// 腾讯云出口IP
];
const
IP_WHITE_SEGMENT
=
[
'10.66.'
,
// 内网IP段
'192.168.'
// 内网IP段
];
const
limiter
=
(
rule
,
policy
,
context
)
=>
{
return
rule
(
context
,
policy
);
...
...
@@ -42,15 +23,12 @@ const limiter = (rule, policy, context) => {
// 排除条件:ip白名单/路径白名单/异步请求/登录用户
const
_excluded
=
(
req
)
=>
{
let
remoteIp
=
req
.
yoho
.
clientIp
||
''
;
let
remoteIpSegment
=
`
$
{
remoteIp
.
split
(
'.'
).
slice
(
0
,
2
).
join
(
'.'
)}.
`
;
return
co
(
function
*
()
{
let
atWhiteList
=
yield
ipWhiteList
(
remoteIp
);
let
at
IP
WhiteList
=
yield
ipWhiteList
(
remoteIp
);
return
Boolean
(
atWhiteList
||
_
.
includes
(
IP_WHITE_LIST
,
remoteIp
)
||
_
.
includes
(
IP_WHITE_SEGMENT
,
remoteIpSegment
)
||
atIPWhiteList
||
_
.
includes
(
pathWhiteList
(),
req
.
path
)
||
req
.
xhr
||
!
_
.
isEmpty
(
_
.
get
(
req
,
'user.uid'
))
...
...
doraemon/middleware/limiter/rules/ip-white-list.js
View file @
f98f280
const
_
=
require
(
'lodash'
);
const
co
=
Promise
.
coroutine
;
const
logger
=
global
.
yoho
.
logger
;
const
cache
=
global
.
yoho
.
cache
.
master
;
const
WHITE_LIST_KEY
=
'whitelist:ip:'
;
const
IP_WHITE_LIST
=
[
'106.38.38.146'
,
// 北京办公区域
'106.38.38.147'
,
// 北京办公区域
'106.39.86.227'
,
// 北京办公区域
'218.94.75.58'
,
// 南京办公区域
'218.94.75.50'
,
// 南京办公区域
'218.94.77.166'
,
// 南京办公区域
// '222.73.196.18', // B站合作方单击次数快加白名单
'123.206.73.107'
,
// 腾讯云出口IP
'139.199.35.21'
,
// 腾讯云出口IP
'139.199.29.44'
,
// 腾讯云出口IP
'123.206.21.19'
// 腾讯云出口IP
];
const
IP_WHITE_SEGMENT
=
[
'10.66.'
,
// 内网IP段
'192.168.'
// 内网IP段
];
module
.
exports
=
(
remoteIp
)
=>
{
let
key
=
`
$
{
WHITE_LIST_KEY
}
$
{
remoteIp
}
`
;
let
remoteIpSegment
=
`
$
{
remoteIp
.
split
(
'.'
).
slice
(
0
,
2
).
join
(
'.'
)}.
`
;
return
co
(
function
*
()
{
if
(
_
.
includes
(
IP_WHITE_LIST
,
remoteIp
)
||
_
.
includes
(
IP_WHITE_SEGMENT
,
remoteIpSegment
))
{
return
true
;
}
let
result
=
Boolean
(
yield
cache
.
getAsync
(
key
));
logger
.
debug
(
key
,
result
);
return
result
;
})();
})().
catch
(
e
=>
{
console
.
error
(
e
);
return
false
;
});
};
...
...
Please
register
or
login
to post a comment