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) });
}
}));