From 8322a580c1f48e506aa6c07ab468908b43298372 Mon Sep 17 00:00:00 2001 From: Christopher Cook Date: Wed, 13 Nov 2024 16:26:25 +0800 Subject: [PATCH] Cloudflare: quote DNS TXT values --- .../DNS/Cloudflare/DnsProviderCloudflare.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Certify.Providers/DNS/Cloudflare/DnsProviderCloudflare.cs b/src/Certify.Providers/DNS/Cloudflare/DnsProviderCloudflare.cs index fc534e09a..e3299248e 100644 --- a/src/Certify.Providers/DNS/Cloudflare/DnsProviderCloudflare.cs +++ b/src/Certify.Providers/DNS/Cloudflare/DnsProviderCloudflare.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; @@ -6,6 +6,7 @@ using Certify.Models.Config; using Certify.Models.Plugins; using Certify.Models.Providers; +using Certify.Models.Shared.Validation; using Certify.Plugins; using Newtonsoft.Json; @@ -203,8 +204,17 @@ private async Task> GetDnsRecords(string zoneId) return records; } + private string NormalizeTXTValue(string val) + { + val = val.Trim("\"".ToCharArray()); + val = $"\"{val}\""; // cloudflare wants TXT value to be quoted + + return val; + } private async Task AddDnsRecord(string zoneId, string name, string value) { + value = NormalizeTXTValue(value); + var request = CreateRequest(HttpMethod.Post, string.Format(_createRecordUri, zoneId)); request.Content = new StringContent( @@ -315,6 +325,7 @@ public async Task DeleteRecord(DnsRecord request) public async Task DeleteRecord(DnsRecord request, bool requireSameValue) { + request.RecordValue = NormalizeTXTValue(request.RecordValue); if (string.IsNullOrEmpty(request.RecordName)) {