File tree Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -24,26 +24,24 @@ const getMountForRequest = function (req) {
24
24
} ;
25
25
26
26
const checkIpRanges = ( ip , ranges = [ ] ) => {
27
- const transformIp = ip => {
28
- if ( ip === '::1' || ip === '::' ) {
29
- ip = '127.0.0.1' ;
30
- }
31
- return ip ;
32
- } ;
33
27
const getType = address => ( isIPv4 ( address ) ? 'ipv4' : 'ipv6' ) ;
28
+ const clientType = getType ( ip ) ;
34
29
const blocklist = new BlockList ( ) ;
35
30
for ( const range of ranges ) {
36
- if ( range . includes ( '/' ) ) {
37
- const [ net , prefix ] = range . split ( '/' ) ;
38
- const addr = transformIp ( net ) ;
31
+ if ( ( range === '::/0' || range === '::' ) && clientType === 'ipv6' ) {
32
+ return true ;
33
+ }
34
+ if ( range === '0.0.0.0' && clientType === 'ipv6' ) {
35
+ return true ;
36
+ }
37
+ const [ addr , prefix ] = range . split ( '/' ) ;
38
+ if ( prefix ) {
39
39
blocklist . addSubnet ( addr , Number ( prefix ) , getType ( addr ) ) ;
40
40
} else {
41
- const addr = transformIp ( range ) ;
42
41
blocklist . addAddress ( addr , getType ( addr ) ) ;
43
42
}
44
43
}
45
- const client = transformIp ( ip ) ;
46
- return blocklist . check ( client , getType ( client ) ) ;
44
+ return blocklist . check ( ip , clientType ) ;
47
45
} ;
48
46
49
47
// Checks that the request is authorized for this app and checks user
You can’t perform that action at this time.
0 commit comments