Stop IDs in a request from being turned into other calls to connected systems

The Tailscale device, Proxmox node, Cloudflare zone/record and Azure record/zone IDs
were put into the outgoing request path as typed. An operator could send a crafted ID
("x/../../tailnet/-/keys/k1") and make the app call a different endpoint than the button
meant -- delete an auth key instead of a device, stop every guest on a node, delete a whole
DNS zone -- under the integration's own credential. Gitea and Dockhand encoded their IDs but
still passed "..".

- utils/pathSegment.ts: checks an ID against what a real one looks like, then encodes it
  (encodeURIComponent alone leaves ".." untouched). Used by the Tailscale, Proxmox,
  Cloudflare, Azure, Gitea and Dockhand adapters.
- The routes refuse a bad ID with a 400 before anything is sent, and the DNS routes turn the
  adapters' refusal into a 400. A server's Proxmox node name is validated when saved.
- Azure: a zone ID without "::" is now refused instead of being cut into two bogus pieces.
- Regression tests (npm test --workspace server, Node's built-in runner): the crafted IDs
  are refused for every adapter and route, real IDs still work, viewers are still refused.
  Against the old code 13 of the 22 tests fail.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-06 21:02:22 +02:00
1 parent fae7089448
commit a641211484
13 files changed
+549 -26

No files matched your search

+9
View File
@@ -15,6 +15,7 @@ import { createDnsAdapter } from "../dns/registry.js";
import { loadDnsProviderConfig, getDnsAdapterForProvider } from "../dns/loadProvider.js";
import { getDnsStats } from "../dns/stats.js";
import { asyncHandler } from "../utils/asyncHandler.js";
import { InvalidIdentifierError } from "../utils/pathSegment.js";
import { notifyDnsRecordAdded, notifyDnsRecordUpdated, notifyDnsRecordDeleted } from "../services/notify.js";
async function zoneNameFor(providerId: number, zoneId: string): Promise<string> {
@@ -354,6 +355,8 @@ dnsRouter.post("/providers/:id/zones/:zoneId/sync", requireRole("operator"), asy
res.json({ records, syncedAt: now });
} catch (err) {
// A zone or record ID that isn't the kind of ID this provider uses (see utils/pathSegment.ts) — nothing was sent.
if (err instanceof InvalidIdentifierError) return res.status(400).json({ error: "invalid_id", message: err.message });
res.status(502).json({ error: err instanceof Error ? err.message : String(err) });
}
}));
@@ -406,6 +409,8 @@ dnsRouter.post("/providers/:id/zones/:zoneId/records", requireRole("operator"),
res.status(201).json({ record: result });
} catch (err) {
// A zone or record ID that isn't the kind of ID this provider uses (see utils/pathSegment.ts) — nothing was sent.
if (err instanceof InvalidIdentifierError) return res.status(400).json({ error: "invalid_id", message: err.message });
res.status(502).json({ error: err instanceof Error ? err.message : String(err) });
}
}));
@@ -459,6 +464,8 @@ dnsRouter.put("/providers/:id/zones/:zoneId/records/:recordId", requireRole("ope
res.json({ record: result });
} catch (err) {
// A zone or record ID that isn't the kind of ID this provider uses (see utils/pathSegment.ts) — nothing was sent.
if (err instanceof InvalidIdentifierError) return res.status(400).json({ error: "invalid_id", message: err.message });
res.status(502).json({ error: err instanceof Error ? err.message : String(err) });
}
}));
@@ -510,6 +517,8 @@ dnsRouter.delete("/providers/:id/zones/:zoneId/records/:recordId", requireRole("
res.status(204).end();
} catch (err) {
// A zone or record ID that isn't the kind of ID this provider uses (see utils/pathSegment.ts) — nothing was sent.
if (err instanceof InvalidIdentifierError) return res.status(400).json({ error: "invalid_id", message: err.message });
res.status(502).json({ error: err instanceof Error ? err.message : String(err) });
}
}));
+18
View File
@@ -25,6 +25,7 @@ import { createPbsAdapter } from "../integrations/pbs/adapter.js";
import { createOsTicketAdapter } from "../integrations/osticket/adapter.js";
import { attachMatchedServers, summarizeMonitors, toMatchableServers } from "../services/uptimeKumaMatch.js";
import { asyncHandler } from "../utils/asyncHandler.js";
import { ID_PATTERNS, isValidId } from "../utils/pathSegment.js";
export const integrationsRouter = Router();
@@ -315,6 +316,12 @@ integrationsRouter.post("/test", requireRole("admin"), asyncHandler(async (req,
res.json(result);
}));
// IDs taken from the URL end up in the request made to the connected system, under the integration's own credential. They're
// checked here (clear 400, nothing sent) and again inside each adapter (see utils/pathSegment.ts) — either alone would do.
function rejectInvalidId(res: Response, what: string) {
return res.status(400).json({ error: "invalid_id", message: `That isn't a valid ${what}.` });
}
// ─── Tailscale ───────────────────────────────────────────────────────────────
/**
@@ -370,6 +377,8 @@ integrationsRouter.post(
const found = await requireTailscaleAdapter(req, res);
if (!found) return;
if (!isValidId(req.params.deviceId, ID_PATTERNS.tailscaleDevice)) return rejectInvalidId(res, "device ID");
const parsed = authorizeSchema.safeParse(req.body);
if (!parsed.success) {
return res.status(400).json({ error: "invalid_body", details: parsed.error.flatten() });
@@ -399,6 +408,8 @@ integrationsRouter.delete(
const found = await requireTailscaleAdapter(req, res);
if (!found) return;
if (!isValidId(req.params.deviceId, ID_PATTERNS.tailscaleDevice)) return rejectInvalidId(res, "device ID");
try {
await found.adapter.deleteDevice(req.params.deviceId);
await recordAudit({
@@ -455,6 +466,9 @@ integrationsRouter.post(
const found = await requireGiteaAdapter(req, res);
if (!found) return;
if (!isValidId(req.params.owner, ID_PATTERNS.giteaName)) return rejectInvalidId(res, "repository owner");
if (!isValidId(req.params.repo, ID_PATTERNS.giteaName)) return rejectInvalidId(res, "repository name");
const runId = Number(req.params.runId);
if (!Number.isInteger(runId)) {
return res.status(400).json({ error: "invalid_run_id" });
@@ -549,6 +563,8 @@ for (const action of dockhandActions) {
const found = await requireDockhandAdapter(req, res);
if (!found) return;
if (!isValidId(req.params.containerId, ID_PATTERNS.container)) return rejectInvalidId(res, "container ID");
const envId = Number(req.params.envId);
if (!Number.isInteger(envId)) {
return res.status(400).json({ error: "invalid_environment_id" });
@@ -716,6 +732,8 @@ for (const action of proxmoxActions) {
const found = await requireProxmoxAdapter(req, res);
if (!found) return;
if (!isValidId(req.params.node, ID_PATTERNS.proxmoxNode)) return rejectInvalidId(res, "node name");
const vmid = Number(req.params.vmid);
if (!Number.isInteger(vmid)) {
return res.status(400).json({ error: "invalid_vmid" });
+2 -1
View File
@@ -7,6 +7,7 @@ import { requireAuth, requireRole } from "../auth/middleware.js";
import { generateApiToken } from "../services/tokens.js";
import { recordAudit } from "../services/audit.js";
import { asyncHandler } from "../utils/asyncHandler.js";
import { ID_PATTERNS } from "../utils/pathSegment.js";
import { loadIntegrationConfig } from "../integrations/loadIntegration.js";
import { createProxmoxAdapter, type ProxmoxGuestType } from "../integrations/proxmox/adapter.js";
import { serverPortsRouter } from "./serverPorts.js";
@@ -106,7 +107,7 @@ const updateServerSchema = z
hostname: z.string().max(255).optional(),
description: z.string().max(500).optional(),
proxmoxIntegrationId: z.number().int().nullable().optional(),
proxmoxNode: z.string().nullable().optional(),
proxmoxNode: z.string().regex(ID_PATTERNS.proxmoxNode, "Not a valid Proxmox node name.").nullable().optional(),
proxmoxGuestType: z.enum(["qemu", "lxc"]).nullable().optional(),
proxmoxVmid: z.number().int().nullable().optional(),
hideProxmoxLink: z.boolean().optional(),