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
31 changes: 31 additions & 0 deletions plugins/feed-discovery/src/feed-discovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,37 @@ describe("site probing helpers", () => {
await expect(assertSafeHttpUrl("file:///etc/passwd")).rejects.toThrow(/Unsupported URL protocol/);
});

it("blocks reserved and documentation IPv4 SSRF targets", async () => {
// TEST-NET-1 (192.0.2.0/24)
await expect(assertSafeHttpUrl("http://192.0.2.1/feed")).rejects.toThrow(/Blocked internal/);
// TEST-NET-2 (198.51.100.0/24)
await expect(assertSafeHttpUrl("http://198.51.100.1/feed")).rejects.toThrow(/Blocked internal/);
// TEST-NET-3 (203.0.113.0/24)
await expect(assertSafeHttpUrl("http://203.0.113.1/feed")).rejects.toThrow(/Blocked internal/);
// IETF protocol assignments (192.0.0.0/24)
await expect(assertSafeHttpUrl("http://192.0.0.1/feed")).rejects.toThrow(/Blocked internal/);
// Benchmark (198.18.0.0/15)
await expect(assertSafeHttpUrl("http://198.18.0.1/feed")).rejects.toThrow(/Blocked internal/);
await expect(assertSafeHttpUrl("http://198.19.255.255/feed")).rejects.toThrow(/Blocked internal/);
// Multicast (224.0.0.0/4)
await expect(assertSafeHttpUrl("http://224.0.0.1/feed")).rejects.toThrow(/Blocked internal/);
// Reserved (240.0.0.0/4)
await expect(assertSafeHttpUrl("http://240.0.0.1/feed")).rejects.toThrow(/Blocked internal/);
});

it("blocks reserved and documentation IPv6 SSRF targets", async () => {
// Discard-only (100::/64)
await expect(assertSafeHttpUrl("http://[100::]/feed")).rejects.toThrow(/Blocked internal/);
// Benchmark (2001:2::/48)
await expect(assertSafeHttpUrl("http://[2001:2::1]/feed")).rejects.toThrow(/Blocked internal/);
// Documentation (2001:db8::/32)
await expect(assertSafeHttpUrl("http://[2001:db8::1]/feed")).rejects.toThrow(/Blocked internal/);
// Multicast (ff00::/8)
await expect(assertSafeHttpUrl("http://[ff02::1]/feed")).rejects.toThrow(/Blocked internal/);
// Link-local (fe80::/10) — already blocked, verify extended range (feb0::)
await expect(assertSafeHttpUrl("http://[feb0::1]/feed")).rejects.toThrow(/Blocked internal/);
});

it("ignores malformed configured candidate URLs", async () => {
const provider = new WebCandidateFeedProbeProvider({
cacheTtlSeconds: 60,
Expand Down
24 changes: 22 additions & 2 deletions plugins/feed-discovery/src/url-safety.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,17 @@ function isBlockedIp(value: string) {
(a === 169 && b === 254) ||
(a === 172 && b >= 16 && b <= 31) ||
(a === 192 && b === 168) ||
(a === 100 && b >= 64 && b <= 127)
(a === 100 && b >= 64 && b <= 127) ||
// Documentation (TEST-NET-1/2/3)
(a === 192 && b === 0 && parts[2] === 2) ||
(a === 198 && b === 51 && parts[2] === 100) ||
(a === 203 && b === 0 && parts[2] === 113) ||
// IETF protocol assignments (192.0.0.0/24)
(a === 192 && b === 0 && parts[2] === 0) ||
// Benchmark (198.18.0.0/15)
(a === 198 && (b === 18 || b === 19)) ||
// Multicast (224.0.0.0/4) and reserved (240.0.0.0/4)
a >= 224
);
}

Expand Down Expand Up @@ -92,7 +102,17 @@ function isBlockedIp(value: string) {
normalized === "::1" ||
normalized.startsWith("fc") ||
normalized.startsWith("fd") ||
normalized.startsWith("fe80")
normalized.startsWith("fe80") ||
// Discard-only (100::/64)
normalized.startsWith("100::") ||
// Benchmark (2001:2::/48)
normalized.startsWith("2001:2:") ||
// Documentation (2001:db8::/32)
normalized.startsWith("2001:db8:") ||
// Link-local scoped (fe80::/10 — covers fe80 through febf)
/^fe[89ab]/.test(normalized) ||
// Multicast (ff00::/8)
normalized.startsWith("ff")
);
}

Expand Down
Loading