From f71756b119ccf3419c338b446cad030c367920e3 Mon Sep 17 00:00:00 2001 From: Bobban Rydh Date: Tue, 6 Oct 2026 23:45:06 +0200 Subject: [PATCH] Fix editing and deleting DNS records from the cached list The records endpoint returned raw cache rows, whose `id` is this app's own row number (12, 13, ...). The DNS page sends `r.id` back when a record is edited or deleted, so the provider was handed a row number instead of its record id. That only worked straight after a manual Sync, whose response carries the provider's ids; after any save or delete the page reloads from the cache and the problem came back. The ID check added for connected systems now refuses such an id with "That isn't a valid record ID". The list now returns records shaped like a sync's: `id` is the provider's record id. Editing and deleting work from the cached list for every DNS provider. The test checks the list hands out the provider's id, and that deleting with it reaches Cloudflare at the right address; with the old shape it fails. Co-Authored-By: Claude Sonnet 5.5 --- server/src/routes/dns.ts | 13 ++++++++++++- server/test/pathInjection.test.ts | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/server/src/routes/dns.ts b/server/src/routes/dns.ts index 6d8239e..f53977c 100644 --- a/server/src/routes/dns.ts +++ b/server/src/routes/dns.ts @@ -283,10 +283,21 @@ dnsRouter.get("/providers/:id/zones/:zoneId/records", asyncHandler(async (req, r const providerId = Number(req.params.id); const zoneId = req.params.zoneId; - const records = await db + const rows = await db .select() .from(dnsRecordsCache) .where(and(eq(dnsRecordsCache.providerId, providerId), eq(dnsRecordsCache.zoneId, zoneId))); + // Shaped like what the provider returns on a sync: `id` is the provider's own record id, which is what editing and deleting + // send back. A cache row's own `id` is just a row number in this app's database and means nothing to the provider. + const records = rows.map((r) => ({ + id: r.recordId, + type: r.type, + name: r.name, + content: r.content, + ttl: r.ttl, + priority: r.priority, + proxied: r.proxied, + })); const [zoneCache] = await db .select() .from(dnsZonesCache) diff --git a/server/test/pathInjection.test.ts b/server/test/pathInjection.test.ts index 9ffc060..f34a506 100644 --- a/server/test/pathInjection.test.ts +++ b/server/test/pathInjection.test.ts @@ -378,6 +378,23 @@ describe("routes", () => { assert.deepEqual(calls, [{ method: "DELETE", url: `https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records/${RECORD}` }]); }); + test("the cached record list hands out the provider's record id, and that id works for a delete", async () => { + // A row as a sync leaves it: this app's own row number (`id`) next to the provider's record id (`recordId`). + const { db } = await import("../src/db/client.js"); + const { dnsRecordsCache } = await import("../src/db/schema.js"); + await db.insert(dnsRecordsCache).values({ providerId: 1, zoneId: ZONE, recordId: RECORD, type: "A", name: "a.example.com", content: "1.2.3.4", ttl: 300 }); + + assert.equal(await send(operator, "GET", `/api/dns/providers/1/zones/${ZONE}/records`), 200); + const { records } = JSON.parse(lastBody.text) as { records: Record[] }; + const shown = records.find((r) => r.name === "a.example.com")!; + assert.equal(shown.id, RECORD, "the page would send the database row number to the provider instead of its record id"); + assert.deepEqual(Object.keys(shown).sort(), ["content", "id", "name", "priority", "proxied", "ttl", "type"]); + + calls = []; + assert.equal(await send(operator, "DELETE", `/api/dns/providers/1/zones/${ZONE}/records/${encodeURIComponent(String(shown.id))}`), 204, lastBody.text); + assert.deepEqual(calls, [{ method: "DELETE", url: `https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records/${RECORD}` }]); + }); + test("Azure DNS: crafted IDs are a 400, nothing reaches Azure's management API", async () => { for (const bad of ["x/../..", "..", "a?b"]) { calls = [];