Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions backend/src/__tests__/indexerPrivateHost.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, expect, it } from '@jest/globals';
import { isPrivateHost } from '../controllers/indexerController.js';

describe('isPrivateHost', () => {
it('blocks the full 172.16.0.0/12 private range', () => {
expect(isPrivateHost('172.16.0.1')).toBe(true);
expect(isPrivateHost('172.16.255.254')).toBe(true);
expect(isPrivateHost('172.31.255.254')).toBe(true);
});

it('does not classify neighboring public 172 ranges as private', () => {
expect(isPrivateHost('172.15.255.254')).toBe(false);
expect(isPrivateHost('172.32.0.1')).toBe(false);
});
});

Check failure on line 15 in backend/src/__tests__/indexerPrivateHost.test.ts

View workflow job for this annotation

GitHub Actions / backend

Insert `⏎`
4 changes: 2 additions & 2 deletions backend/src/controllers/indexerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import logger from '../utils/logger.js';
* Returns true if the hostname resolves to a private, loopback, or link-local
* address that should never receive outbound webhook deliveries (SSRF guard).
*/
function isPrivateHost(hostname: string): boolean {
export function isPrivateHost(hostname: string): boolean {
// Strip IPv6 brackets
const host = hostname.replace(/^\[|\]$/g, '');

Expand All @@ -34,7 +34,7 @@ function isPrivateHost(hostname: string): boolean {

// Private IPv4 ranges (RFC 1918)
if (/^10\./.test(host)) return true;
if (/^172\.(1[7-9]|2\d|3[01])\./.test(host)) return true;
if (/^172\.(1[6-9]|2\d|3[01])\./.test(host)) return true;
if (/^192\.168\./.test(host)) return true;

// AWS / GCP metadata endpoints
Expand Down
Loading