Skip to content

Commit df0986b

Browse files
committed
fix(dns): apply content normalization in upsert match logic to prevent duplicates
1 parent 91db4e6 commit df0986b

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎packages/server/src/utils/dns/cloudflare.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,16 @@ export const cloudflareClient: DnsClient<CloudflareConfig> = {
175175
`/zones/${record.zoneId}/dns_records?type=${record.type}&name=${encodeURIComponent(record.name)}`,
176176
);
177177

178+
const built = buildValue(record);
179+
const normalizedRecord = {
180+
type: record.type,
181+
content: built.content ?? record.content.trim(),
182+
priority: built.priority,
183+
};
184+
const expectedContent = inlinePriority(normalizedRecord);
185+
178186
const existingRecord = existing.find(
179-
(r) => inlinePriority(r) === record.content,
187+
(r) => inlinePriority(r) === expectedContent,
180188
);
181189
if (existingRecord) {
182190
const updated = await cfFetch<{ id: string }>(

‎packages/server/src/utils/dns/infomaniak.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,14 @@ export const infomaniakClient: DnsClient<InfomaniakConfig> = {
172172
async upsertRecord(config, record) {
173173
const source = toSource(record.name, record.zoneId);
174174
const existing = await listZoneRecords(config, record.zoneId);
175+
const expectedContent = unquoteTarget(
176+
quoteTarget(record.type, record.content),
177+
);
175178
const match = existing.find(
176179
(candidate) =>
177180
candidate.type === record.type &&
178181
normalizeSource(candidate.source) === source &&
179-
unquoteTarget(candidate.target) === record.content,
182+
unquoteTarget(candidate.target) === expectedContent,
180183
);
181184

182185
const body = JSON.stringify(recordPayload(record, record.zoneId));

0 commit comments

Comments
 (0)