Skip to content

Commit 99c2f9e

Browse files
committed
Change loopback regex to avoid valid addresses
1 parent fa2eaf1 commit 99c2f9e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

constants.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,30 @@ export const CONSTANTS = {
3939

4040
REGEX_LOOPBACK: new RegExp(
4141
"^" +
42-
"(?:(?:10|127)(?:\\.\\d{1,3}){3})" +
42+
// Loopback: 127.0.0.0 - 127.255.255.255
43+
"(?:127(?:\\.\\d{1,3}){3})" +
4344
"|" +
44-
"(?:(?:169\\.254|192\\.168|192\\.0)(?:\\.\\d{1,3}){2})" +
45+
// Private Class A: 10.0.0.0 - 10.255.255.255
46+
"(?:10(?:\\.\\d{1,3}){3})" +
4547
"|" +
48+
// Private Class B: 172.16.0.0 - 172.31.255.255
4649
"(?:172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
50+
"|" +
51+
// Private Class C: 192.168.0.0 - 192.168.255.255
52+
"(?:192\\.168(?:\\.\\d{1,3}){2})" +
53+
"|" +
54+
// Link-local: 169.254.0.0 - 169.254.255.255
55+
"(?:169\\.254(?:\\.\\d{1,3}){2})" +
56+
"|" +
57+
// Documentation: 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24
58+
"(?:192\\.0\\.2(?:\\.\\d{1,3}){1})" +
59+
"|" +
60+
"(?:198\\.51\\.100(?:\\.\\d{1,3}){1})" +
61+
"|" +
62+
"(?:203\\.0\\.113(?:\\.\\d{1,3}){1})" +
63+
"|" +
64+
// Carrier-Grade NAT (CGNAT): 100.64.0.0 - 100.127.255.255
65+
"(?:100\\.(?:6[4-9]|[7-9]\\d|1[0-1]\\d)(?:\\.\\d{1,3}){2})" +
4766
"$",
4867
"i"
4968
),

jest.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ module.exports = {
22
preset: `ts-jest`,
33
testEnvironment: `node`,
44
globals: { "ts-jest": { diagnostics: false } },
5+
testPathIgnorePatterns: ["/build/"],
56
};

0 commit comments

Comments
 (0)