⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
fix(net): allow operators to trust named hosts that resolve privately (#317)
Maxwell Burdick257c817dba76
diff --git a/.env.example b/.env.exampleindex b443a0ec..bd4e5cdf 100644--- a/.env.example+++ b/.env.example@@ -72,6 +72,28 @@ APP_ENCRYPTION_KEY=# Same value for all three. openssl rand -base64 32WORKER_INTERNAL_TOKEN=change-me-please-generate-a-real-secret+# ── Outbound request policy (apps/api + apps/worker) ──+# Server-side fetches of a URL that came from a request — a webhook target, an+# attachment to import, a repository host — are refused when the URL resolves to a+# loopback, link-local, or private address. Name a host here to trust it anyway.+#+# The case this exists for is a self-hosted repository host: its address is+# configuration rather than content, and on a self-hosted instance it is normally+# private, so without this a Gitea/Forgejo/GitLab on your own network cannot be+# connected at all. Exact hostnames, comma-separated; no wildcards or CIDR ranges.+# https is still required and the resolved address is still pinned.+#+# A named host is trusted by every outbound path, not only by the repository+# connection. The same list is read wherever a URL is vetted, so naming a host also+# makes it a permitted webhook target — validated by the api when a webhook is+# created or updated, and DELIVERED to by the worker — and a permitted source for+# attachment import. Anyone who can create a webhook or import an attachment can+# therefore reach a host you name here. Name only hosts you would let them reach.+#+# Set it on both the api and the worker: the api vets and the worker delivers, so a+# list on one and not the other silently applies to half the paths above.+# SSRF_ALLOWED_HOSTS=git.internal.example.com+# ── Telegram bot (apps/bot) — the bot token is stored in the DB, not here ──# BOT_CONFIG_POLL_INTERVAL_MS=30000 # how often to re-read bot settings from the API# BOT_CONFIG_RETRY_INTERVAL_MS=5000 # retry delay after the API could not be reacheddiff --git a/docker-compose.coolify-images.yml b/docker-compose.coolify-images.ymlindex 183031ef..1fba56fe 100644--- a/docker-compose.coolify-images.yml+++ b/docker-compose.coolify-images.yml@@ -111,6 +111,9 @@ services:- S3_SECRET_ACCESS_KEY=${SERVICE_PASSWORD_MINIO}- S3_REGION=${S3_REGION:-us-east-1}- S3_FORCE_PATH_STYLE=${S3_FORCE_PATH_STYLE:-}+ # Hosts trusted even though they resolve privately. Also governs webhook URL+ # validation and attachment import.+ - SSRF_ALLOWED_HOSTS=${SSRF_ALLOWED_HOSTS:-}# How long the pre-migration dumps are kept, and the switch that upgrades# without one. BACKUP_DIR is not among them: the volume below pins it.- BACKUP_RETENTION_DAYS=${BACKUP_RETENTION_DAYS:-}@@ -149,6 +152,8 @@ services:TELEMETRY_DISABLED: ${TELEMETRY_DISABLED:-}DO_NOT_TRACK: ${DO_NOT_TRACK:-}TELEMETRY_DEBUG: ${TELEMETRY_DEBUG:-}+ # The same list the api reads. This process delivers webhooks to those hosts.+ SSRF_ALLOWED_HOSTS: ${SSRF_ALLOWED_HOSTS:-}# Optional tuning — defaults live in apps/worker/src/config.ts:# WEBHOOK_POLL_INTERVAL_MS, WEBHOOK_BATCH_SIZE, WEBHOOK_TIMEOUT_MS,# WEBHOOK_MAX_ATTEMPTS, WEBHOOK_DISABLE_THRESHOLD, WEBHOOK_LEASE_SECONDS,diff --git a/docker-compose.coolify.yml b/docker-compose.coolify.ymlindex 4894bc41..1d8673b7 100644--- a/docker-compose.coolify.yml+++ b/docker-compose.coolify.yml@@ -106,6 +106,9 @@ services:S3_SECRET_ACCESS_KEY: ${SERVICE_PASSWORD_MINIO}S3_REGION: ${S3_REGION:-us-east-1}S3_FORCE_PATH_STYLE: ${S3_FORCE_PATH_STYLE:-}+ # Hosts trusted even though they resolve privately. Also governs webhook URL+ # validation and attachment import.+ SSRF_ALLOWED_HOSTS: ${SSRF_ALLOWED_HOSTS:-}# How long the pre-migration dumps are kept, and the switch that upgrades# without one. BACKUP_DIR is not among them: the volume below pins it.BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-}@@ -149,6 +152,8 @@ services:TELEMETRY_DISABLED: ${TELEMETRY_DISABLED:-}DO_NOT_TRACK: ${DO_NOT_TRACK:-}TELEMETRY_DEBUG: ${TELEMETRY_DEBUG:-}+ # The same list the api reads. This process delivers webhooks to those hosts.+ SSRF_ALLOWED_HOSTS: ${SSRF_ALLOWED_HOSTS:-}# Optional tuning — defaults live in apps/worker/src/config.ts:# WEBHOOK_POLL_INTERVAL_MS, WEBHOOK_BATCH_SIZE, WEBHOOK_TIMEOUT_MS,# WEBHOOK_MAX_ATTEMPTS, WEBHOOK_DISABLE_THRESHOLD, WEBHOOK_LEASE_SECONDS,diff --git a/docker-compose.yml b/docker-compose.ymlindex 7c32e963..67dc1e50 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -107,6 +107,9 @@ services:S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY}S3_REGION: ${S3_REGION:-us-east-1}S3_FORCE_PATH_STYLE: ${S3_FORCE_PATH_STYLE:-}+ # Hosts trusted even though they resolve privately. Also governs webhook URL+ # validation and attachment import.+ SSRF_ALLOWED_HOSTS: ${SSRF_ALLOWED_HOSTS:-}# How long the pre-migration dumps are kept, and the switch that upgrades# without one. BACKUP_DIR is not among them: the volume below pins it.BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-}@@ -149,6 +152,8 @@ services:TELEMETRY_DISABLED: ${TELEMETRY_DISABLED:-}DO_NOT_TRACK: ${DO_NOT_TRACK:-}TELEMETRY_DEBUG: ${TELEMETRY_DEBUG:-}+ # The same list the api reads. This process delivers webhooks to those hosts.+ SSRF_ALLOWED_HOSTS: ${SSRF_ALLOWED_HOSTS:-}# Optional tuning lives in apps/worker/src/config.ts.# Telegram bot: long polling for the instance bot, completing the account linksdiff --git a/packages/net/src/__tests__/pinned-fetch.test.ts b/packages/net/src/__tests__/pinned-fetch.test.tsindex 16ebc677..835befa1 100644--- a/packages/net/src/__tests__/pinned-fetch.test.ts+++ b/packages/net/src/__tests__/pinned-fetch.test.ts@@ -1,5 +1,5 @@-import { describe, it, expect } from 'bun:test';-import { pinnedFetch, UrlNotAllowedError } from '../index';+import { describe, it, expect, afterEach } from 'bun:test';+import { assertPublicHttpUrl, pinnedFetch, UrlNotAllowedError } from '../index';// The guard is strict under NODE_ENV=test, so these exercise the production rules.describe('pinnedFetch', () => {@@ -24,3 +24,55 @@ describe('pinnedFetch', () => {expect((await res.text()).length).toBeGreaterThan(0);});});++// SSRF_ALLOWED_HOSTS is the operator's escape hatch for a self-hosted repository+// host: its address is configuration rather than content, and on a self-hosted+// instance it is normally private. These run under NODE_ENV=test, so the strict+// rules apply and the allowlist is the only thing admitting the URL.+describe('SSRF_ALLOWED_HOSTS', () => {+ const saved = process.env.SSRF_ALLOWED_HOSTS;+ afterEach(() => {+ if (saved === undefined) delete process.env.SSRF_ALLOWED_HOSTS;+ else process.env.SSRF_ALLOWED_HOSTS = saved;+ });++ it('admits a literal private address that is named', async () => {+ delete process.env.SSRF_ALLOWED_HOSTS;+ await expect(assertPublicHttpUrl('https://127.0.0.1/')).rejects.toBeInstanceOf(+ UrlNotAllowedError,+ );+ process.env.SSRF_ALLOWED_HOSTS = '127.0.0.1';+ expect((await assertPublicHttpUrl('https://127.0.0.1/')).hostname).toBe('127.0.0.1');+ });++ it('admits a public hostname that resolves privately when it is named', async () => {+ process.env.SSRF_ALLOWED_HOSTS = 'localtest.me';+ expect((await assertPublicHttpUrl('https://localtest.me/')).hostname).toBe('localtest.me');+ });++ it('reads a comma-separated list, ignoring spacing and case', async () => {+ process.env.SSRF_ALLOWED_HOSTS = ' git.example.com , LOCALTEST.ME ';+ expect((await assertPublicHttpUrl('https://localtest.me/')).hostname).toBe('localtest.me');+ });++ it('matches the exact host only — no suffix or wildcard matching', async () => {+ process.env.SSRF_ALLOWED_HOSTS = 'localtest.me';+ await expect(assertPublicHttpUrl('https://sub.localtest.me/')).rejects.toBeInstanceOf(+ UrlNotAllowedError,+ );+ });++ it('does not relax the https requirement for a named host', async () => {+ process.env.SSRF_ALLOWED_HOSTS = 'localtest.me';+ await expect(assertPublicHttpUrl('http://localtest.me/')).rejects.toBeInstanceOf(+ UrlNotAllowedError,+ );+ });++ it('exempts nothing when unset', async () => {+ delete process.env.SSRF_ALLOWED_HOSTS;+ await expect(assertPublicHttpUrl('https://localtest.me/')).rejects.toBeInstanceOf(+ UrlNotAllowedError,+ );+ });+});diff --git a/packages/net/src/index.ts b/packages/net/src/index.tsindex 3b86f3e5..90a7177d 100644--- a/packages/net/src/index.ts+++ b/packages/net/src/index.ts@@ -8,6 +8,9 @@ import { request as httpsRequest } from 'node:https';// services (including the cloud metadata endpoint at 169.254.169.254), so those are// rejected. The check resolves DNS, so a public hostname that points at a private// address is caught too.+//+// SSRF_ALLOWED_HOSTS names the hosts an operator has decided to trust anyway — see+// isAllowedHost below. It is empty by default.export class UrlNotAllowedError extends Error {}@@ -16,6 +19,32 @@ function isLocalHostname(host: string): boolean {return host === 'localhost' || host.endsWith('.local');}+// Hosts the operator has explicitly trusted even though they resolve privately.+//+// The rules above are right for a URL that arrives as content — a webhook target, an+// attachment to import. A self-hosted repository host is different: its address is+// configuration, entered by someone who already administers the project's+// integrations, and on a self-hosted instance it is normally a private one. Without+// an escape hatch, connecting an instance to a Gitea, Forgejo, or GitLab on the same+// network cannot be expressed at all.+//+// Empty by default, so nothing is exempt unless it is named. Matching is on the exact+// hostname — no wildcards, no CIDR ranges, no suffix matching — so naming one host+// trusts one host. Everything else still applies to it: https is still required, and+// the resolved address is still pinned, so a name on this list cannot be used to+// mount a DNS-rebinding attack either.+//+// Read per call rather than at module load so a test can set it around one case.+function isAllowedHost(host: string): boolean {+ const configured = process.env.SSRF_ALLOWED_HOSTS;+ if (!configured) return false;+ return configured+ .split(',')+ .map((entry) => entry.trim().toLowerCase())+ .filter(Boolean)+ .includes(host);+}+// IPv4-mapped and IPv4-compatible IPv6 addresses (`::ffff:127.0.0.1`, `::ffff:7f00:1`,// `::127.0.0.1`) reach the same host as the IPv4 they carry, so they are compared as// that IPv4 rather than as an IPv6 the range checks below would not recognise.@@ -75,8 +104,9 @@ async function vet(raw: string): Promise<{ url: URL; pin?: Pin }> {}const host = url.hostname.toLowerCase().replace(/^\[|\]$/g, '');+ const allowed = isAllowedHost(host);if (isLocalHostname(host) || isPrivateIp(host)) {- if (!devRelaxed) {+ if (!devRelaxed && !allowed) {throw new UrlNotAllowedError('url must not point to a private or local address');}return { url };@@ -88,7 +118,7 @@ async function vet(raw: string): Promise<{ url: URL; pin?: Pin }> {} catch {throw new UrlNotAllowedError('url host could not be resolved');}- if (addrs.some((a) => isPrivateIp(a.address)) && !devRelaxed) {+ if (addrs.some((a) => isPrivateIp(a.address)) && !devRelaxed && !allowed) {throw new UrlNotAllowedError('url must not point to a private or local address');}return { url, pin: addrs[0] };