import { test } from 'node:test' import assert from 'node:assert/strict' import { isPrivateAddress, assertPublicHttpsUrl } from '../server/url-safety.js' test('private, loopback, link-local and tailscale addresses are flagged', () => { for (const ip of ['127.0.0.1', '10.0.0.5', '192.168.1.1', '172.16.0.1', '169.254.169.254', '100.64.1.1', '::1', 'fd00::1', 'fe80::1', '::ffff:10.0.0.1']) { assert.ok(isPrivateAddress(ip), ip) } for (const ip of ['8.8.8.8', '1.1.1.1', '2606:4700:4700::1111']) assert.ok(!isPrivateAddress(ip), ip) }) test('assertPublicHttpsUrl rejects unsafe URLs', async () => { for (const url of ['http://example.com', 'https://localhost/x', 'https://127.0.0.1/', 'https://169.254.169.254/latest', 'https://user:pw@example.com', 'https://nas.local/hook', 'not a url']) { await assert.rejects(() => assertPublicHttpsUrl(url), url) } await assert.doesNotReject(() => assertPublicHttpsUrl('https://8.8.8.8/hook')) })