mirror of
https://github.com/fosrl/pangolin.git
synced 2026-11-29 02:52:57 +00:00
AI provider upstreamUrl was only z.url() and the AI gateway streamed the upstream response back, so any org admin could read internal services, Pangolin's own internal API or the cloud metadata service (prod had a provider pointed at 169.254.169.254). Alert webhooks and HTTP log streaming fetched any URL and followed redirects. - server/lib/outboundAddress.ts (no config dependency, unit tested): always refuses loopback, unspecified, link-local, broadcast, multicast and reserved addresses (incl. IPv4-mapped forms), localhost and Pangolin's own service names; refuses RFC1918/ULA/CGNAT when private outbound is blocked. Provides a resolver check and a connect-time DNS lookup so rebinding cannot get around it. - server/lib/outboundUrlGuard.ts: policy from config. New flags.block_private_outbound_urls defaults to on for SaaS, off for self-hosted (local models). - aiGatewayUpstreamFetch checks the host and passes the guarded lookup to every upstream request; create/updateAiProvider reject blocked URLs. - sendAlertWebhook and HttpLogDestination check the URL before sending and no longer follow redirects. - Migration notes cover the flag and a query for providers that will stop working. PAN-1799 (3v9x, 4g5q)
99 lines
2.4 KiB
TypeScript
99 lines
2.4 KiB
TypeScript
import { assertEquals } from "@test/assert";
|
|
import {
|
|
outboundAddressBlockReason,
|
|
outboundHostBlockReason
|
|
} from "./outboundAddress";
|
|
|
|
const selfHosted = { allowPrivate: true, reservedHostnames: ["pangolin"] };
|
|
const saas = { allowPrivate: false, reservedHostnames: ["pangolin"] };
|
|
|
|
function testAddresses() {
|
|
console.log("Running outbound address tests...");
|
|
const alwaysBlocked = [
|
|
"127.0.0.1",
|
|
"::1",
|
|
"0.0.0.0",
|
|
"::",
|
|
"169.254.169.254",
|
|
"fe80::1",
|
|
"::ffff:169.254.169.254",
|
|
"::ffff:127.0.0.1",
|
|
"224.0.0.1",
|
|
"255.255.255.255"
|
|
];
|
|
for (const a of alwaysBlocked) {
|
|
assertEquals(
|
|
outboundAddressBlockReason(a, selfHosted) !== null,
|
|
true,
|
|
`${a} blocked self-hosted`
|
|
);
|
|
assertEquals(
|
|
outboundAddressBlockReason(a, saas) !== null,
|
|
true,
|
|
`${a} blocked saas`
|
|
);
|
|
}
|
|
const privateAddrs = [
|
|
"10.0.0.1",
|
|
"172.17.0.1",
|
|
"192.168.1.5",
|
|
"fd00::1",
|
|
"100.89.0.1"
|
|
];
|
|
for (const a of privateAddrs) {
|
|
assertEquals(
|
|
outboundAddressBlockReason(a, selfHosted),
|
|
null,
|
|
`${a} allowed self-hosted`
|
|
);
|
|
assertEquals(
|
|
outboundAddressBlockReason(a, saas) !== null,
|
|
true,
|
|
`${a} blocked saas`
|
|
);
|
|
}
|
|
for (const a of ["8.8.8.8", "1.1.1.1", "2606:4700:4700::1111"]) {
|
|
assertEquals(outboundAddressBlockReason(a, saas), null, `${a} allowed`);
|
|
}
|
|
}
|
|
|
|
function testHosts() {
|
|
console.log("Running outbound host tests...");
|
|
for (const h of [
|
|
"localhost",
|
|
"a.localhost",
|
|
"pangolin",
|
|
"api.pangolin",
|
|
"PANGOLIN.",
|
|
"127.0.0.1",
|
|
"[::1]",
|
|
"2130706433"
|
|
]) {
|
|
assertEquals(
|
|
outboundHostBlockReason(h, selfHosted) !== null,
|
|
true,
|
|
`${h} blocked`
|
|
);
|
|
}
|
|
for (const h of [
|
|
"api.openai.com",
|
|
"ollama",
|
|
"pangolin.net",
|
|
"my-pangolin"
|
|
]) {
|
|
assertEquals(
|
|
outboundHostBlockReason(h, selfHosted),
|
|
null,
|
|
`${h} allowed before DNS`
|
|
);
|
|
}
|
|
}
|
|
|
|
try {
|
|
testAddresses();
|
|
testHosts();
|
|
console.log("All outbound address tests passed!");
|
|
} catch (error) {
|
|
console.error("Test failed:", error);
|
|
process.exit(1);
|
|
}
|