Skip to content

Commit 7e67f33

Browse files
author
Larify
committedDec 30, 2021
fetch cloudflare ipv4/ipv6 fail NginxProxyManager#1405
1 parent adc5a20 commit 7e67f33

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed
 

‎backend/internal/ip_ranges.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const CLOUDFRONT_URL = 'https://ip-ranges.amazonaws.com/ip-ranges.json';
99
const CLOUDFARE_V4_URL = 'https://www.cloudflare.com/ips-v4';
1010
const CLOUDFARE_V6_URL = 'https://www.cloudflare.com/ips-v6';
1111

12+
const regIpV4 = /^(\d+\.?){4}\/\d+/;
13+
const regIpV6 = /^(([\da-fA-F]+)?:)+\/\d+/;
14+
1215
const internalIpRanges = {
1316

1417
interval_timeout: 1000 * 60 * 60 * 6, // 6 hours
@@ -74,14 +77,14 @@ const internalIpRanges = {
7477
return internalIpRanges.fetchUrl(CLOUDFARE_V4_URL);
7578
})
7679
.then((cloudfare_data) => {
77-
let items = cloudfare_data.split('\n');
80+
let items = cloudfare_data.split('\n').filter((line) => regIpV4.test(line));
7881
ip_ranges = [... ip_ranges, ... items];
7982
})
8083
.then(() => {
8184
return internalIpRanges.fetchUrl(CLOUDFARE_V6_URL);
8285
})
8386
.then((cloudfare_data) => {
84-
let items = cloudfare_data.split('\n');
87+
let items = cloudfare_data.split('\n').filter((line) => regIpV6.test(line));
8588
ip_ranges = [... ip_ranges, ... items];
8689
})
8790
.then(() => {

0 commit comments

Comments
 (0)
Please sign in to comment.