Skip to content

Commit

Permalink
Change loopback regex to avoid valid addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
ospfranco committed Oct 21, 2024
1 parent fa2eaf1 commit 99c2f9e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,30 @@ export const CONSTANTS = {

REGEX_LOOPBACK: new RegExp(
"^" +
"(?:(?:10|127)(?:\\.\\d{1,3}){3})" +
// Loopback: 127.0.0.0 - 127.255.255.255
"(?:127(?:\\.\\d{1,3}){3})" +
"|" +
"(?:(?:169\\.254|192\\.168|192\\.0)(?:\\.\\d{1,3}){2})" +
// Private Class A: 10.0.0.0 - 10.255.255.255
"(?:10(?:\\.\\d{1,3}){3})" +
"|" +
// Private Class B: 172.16.0.0 - 172.31.255.255
"(?:172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
"|" +
// Private Class C: 192.168.0.0 - 192.168.255.255
"(?:192\\.168(?:\\.\\d{1,3}){2})" +
"|" +
// Link-local: 169.254.0.0 - 169.254.255.255
"(?:169\\.254(?:\\.\\d{1,3}){2})" +
"|" +
// Documentation: 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24
"(?:192\\.0\\.2(?:\\.\\d{1,3}){1})" +
"|" +
"(?:198\\.51\\.100(?:\\.\\d{1,3}){1})" +
"|" +
"(?:203\\.0\\.113(?:\\.\\d{1,3}){1})" +
"|" +
// Carrier-Grade NAT (CGNAT): 100.64.0.0 - 100.127.255.255
"(?:100\\.(?:6[4-9]|[7-9]\\d|1[0-1]\\d)(?:\\.\\d{1,3}){2})" +
"$",
"i"
),
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = {
preset: `ts-jest`,
testEnvironment: `node`,
globals: { "ts-jest": { diagnostics: false } },
testPathIgnorePatterns: ["/build/"],
};

0 comments on commit 99c2f9e

Please sign in to comment.