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)
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import type { LookupFunction } from "node:net";
|
|
import config from "@server/lib/config";
|
|
import { build } from "@server/build";
|
|
import {
|
|
assertSafeOutboundUrlWith,
|
|
guardedLookupWith,
|
|
OutboundPolicy,
|
|
OutboundUrlError
|
|
} from "@server/lib/outboundAddress";
|
|
|
|
export { OutboundUrlError };
|
|
|
|
export function getOutboundPolicy(): OutboundPolicy {
|
|
const raw = config.getRawConfig();
|
|
const blockPrivate =
|
|
raw.flags?.block_private_outbound_urls ?? build === "saas";
|
|
return {
|
|
allowPrivate: !blockPrivate,
|
|
reservedHostnames: [
|
|
raw.server.internal_hostname,
|
|
"gerbil",
|
|
"traefik",
|
|
"badger",
|
|
"host.docker.internal",
|
|
"metadata.google.internal"
|
|
].filter(Boolean)
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Throws OutboundUrlError unless the URL is http(s) and every address its
|
|
* host resolves to is allowed by the server's outbound policy.
|
|
*/
|
|
export function assertSafeOutboundUrl(
|
|
url: string,
|
|
policy: OutboundPolicy = getOutboundPolicy()
|
|
): Promise<void> {
|
|
return assertSafeOutboundUrlWith(url, policy);
|
|
}
|
|
|
|
/** DNS lookup for http(s).request that refuses blocked addresses. */
|
|
export function guardedLookup(
|
|
policy: OutboundPolicy = getOutboundPolicy()
|
|
): LookupFunction {
|
|
return guardedLookupWith(policy);
|
|
}
|