Skip to content

Commit 7bcd375

Browse files
authored
Merge pull request #155 from OP-Engineering/oscar/change-loopback-regex
Change loopback regex to avoid valid addresses
2 parents fa2eaf1 + 8954cee commit 7bcd375

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

Diff for: .github/workflows/tests.yml

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1-
name: Repo checks
2-
3-
on: [push, pull_request]
1+
name: Tests
2+
on: pull_request
43

54
jobs:
65
tests:
76
runs-on: ubuntu-latest
87

98
steps:
10-
- uses: actions/checkout@v2
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
12+
- name: Cache dependencies
13+
id: yarn-cache
14+
uses: actions/cache@v3
15+
with:
16+
path: |
17+
**/node_modules
18+
.yarn/install-state.gz
19+
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}-${{ hashFiles('**/package.json', '!node_modules/**') }}
20+
restore-keys: |
21+
${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
22+
${{ runner.os }}-yarn-
1123
12-
- name: Install dependencies
13-
run: yarn
24+
- name: Install dependencies
25+
run: yarn
1426

15-
- name: Run tests
16-
uses: yarn test
27+
- name: Run tests
28+
run: yarn test

Diff for: 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
),

Diff for: 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)