diff --git a/backend/internal/ip_ranges.js b/backend/internal/ip_ranges.js index edf5c3a..40e63ea 100644 --- a/backend/internal/ip_ranges.js +++ b/backend/internal/ip_ranges.js @@ -9,6 +9,9 @@ const CLOUDFRONT_URL = 'https://ip-ranges.amazonaws.com/ip-ranges.json'; const CLOUDFARE_V4_URL = 'https://www.cloudflare.com/ips-v4'; const CLOUDFARE_V6_URL = 'https://www.cloudflare.com/ips-v6'; +const regIpV4 = /^(\d+\.?){4}\/\d+/; +const regIpV6 = /^(([\da-fA-F]+)?:)+\/\d+/; + const internalIpRanges = { interval_timeout: 1000 * 60 * 60 * 6, // 6 hours @@ -74,14 +77,14 @@ const internalIpRanges = { return internalIpRanges.fetchUrl(CLOUDFARE_V4_URL); }) .then((cloudfare_data) => { - let items = cloudfare_data.split('\n'); + let items = cloudfare_data.split('\n').filter((line) => regIpV4.test(line)); ip_ranges = [... ip_ranges, ... items]; }) .then(() => { return internalIpRanges.fetchUrl(CLOUDFARE_V6_URL); }) .then((cloudfare_data) => { - let items = cloudfare_data.split('\n'); + let items = cloudfare_data.split('\n').filter((line) => regIpV6.test(line)); ip_ranges = [... ip_ranges, ... items]; }) .then(() => {