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:
1 parent
fae7089448
commit
a641211484
13 files changed
+549
-26
No files matched your search
@@ -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" });
|
||||
|
||||
Reference in new issue
Block a user