Skip to content

Commit 8f5d140

Browse files
committed
Refactor webhook endpoint validation to utilize BLOCKED_HOSTNAMES and ALLOWED_PORTS constants from ipValidator module, improving code organization and maintainability.
1 parent 9b2935e commit 8f5d140

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/utils/ipValidator.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,22 @@ export function isPrivateIP(ip: string): boolean {
4343

4444
return PRIVATE_IP_PATTERNS.some((pattern) => pattern.test(bare));
4545
}
46+
47+
/**
48+
* Hostnames blocked regardless of DNS resolution
49+
*/
50+
export const BLOCKED_HOSTNAMES: RegExp[] = [
51+
/^localhost$/i,
52+
/\.local$/i,
53+
/\.internal$/i,
54+
/\.lan$/i,
55+
/\.localdomain$/i,
56+
];
57+
58+
/**
59+
* Only these ports are allowed for webhook delivery
60+
*/
61+
export const ALLOWED_PORTS: Record<string, number> = {
62+
'http:': 80,
63+
'https:': 443,
64+
};

src/utils/webhookEndpointValidator.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
import dns from 'dns';
2-
import { isPrivateIP } from './ipValidator';
3-
4-
/**
5-
* Hostnames blocked regardless of DNS resolution
6-
*/
7-
const BLOCKED_HOSTNAMES: RegExp[] = [
8-
/^localhost$/i,
9-
/\.local$/i,
10-
/\.internal$/i,
11-
/\.lan$/i,
12-
/\.localdomain$/i,
13-
];
14-
15-
/**
16-
* Only these ports are allowed for webhook delivery
17-
*/
18-
const ALLOWED_PORTS: Record<string, number> = {
19-
'http:': 80,
20-
'https:': 443,
21-
};
2+
import { isPrivateIP, BLOCKED_HOSTNAMES, ALLOWED_PORTS } from './ipValidator';
223

234
/**
245
* Validates a webhook endpoint URL for SSRF safety.

0 commit comments

Comments
 (0)