Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/url-guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function isInternalUrl(raw: string): boolean {
// Reject non-numeric ports; odd ports can hide alternate protocols.
if (u.port !== "" && !/^\d{1,5}$/.test(u.port)) return true;

const h = u.hostname.toLowerCase();
const h = u.hostname.toLowerCase().replace(/\.+$/, "");
if (h === "localhost" || h.endsWith(".localhost") || h === "metadata.google.internal") return true;
if (h === "0.0.0.0") return true;

Expand Down
6 changes: 6 additions & 0 deletions tests/url-guard.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ test("SSRF guard blocks internal IPv4 special-use ranges", () => {
assert.equal(isInternalUrl("http://198.19.255.254/hook"), true);
});

test("SSRF guard blocks internal hostnames with DNS root dots", () => {
assert.equal(isInternalUrl("http://localhost./hook"), true);
assert.equal(isInternalUrl("http://app.localhost./hook"), true);
assert.equal(isInternalUrl("http://metadata.google.internal./hook"), true);
});

test("SSRF guard allows public IPv6 webhook targets", () => {
assert.equal(isInternalUrl("https://[2606:4700:4700::1111]/hook"), false);
assert.equal(isInternalUrl("https://[::ffff:8.8.8.8]/hook"), false);
Expand Down
Loading