Skip to content

Commit 6602acf

Browse files
committed
Update middlewares.js
1 parent c2fdbd7 commit 6602acf

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/middlewares.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,24 @@ const getMountForRequest = function (req) {
2424
};
2525

2626
const checkIpRanges = (ip, ranges = []) => {
27-
const transformIp = ip => {
28-
if (ip === '::1' || ip === '::') {
29-
ip = '127.0.0.1';
30-
}
31-
return ip;
32-
};
3327
const getType = address => (isIPv4(address) ? 'ipv4' : 'ipv6');
28+
const clientType = getType(ip);
3429
const blocklist = new BlockList();
3530
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) {
3939
blocklist.addSubnet(addr, Number(prefix), getType(addr));
4040
} else {
41-
const addr = transformIp(range);
4241
blocklist.addAddress(addr, getType(addr));
4342
}
4443
}
45-
const client = transformIp(ip);
46-
return blocklist.check(client, getType(client));
44+
return blocklist.check(ip, clientType);
4745
};
4846

4947
// Checks that the request is authorized for this app and checks user

0 commit comments

Comments
 (0)