Skip to content

Commit

Permalink
Cloudflare: quote DNS TXT values
Browse files Browse the repository at this point in the history
  • Loading branch information
webprofusion-chrisc committed Nov 13, 2024
1 parent a2fb31e commit 8322a58
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Certify.Providers/DNS/Cloudflare/DnsProviderCloudflare.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Certify.Models.Config;
using Certify.Models.Plugins;
using Certify.Models.Providers;
using Certify.Models.Shared.Validation;
using Certify.Plugins;
using Newtonsoft.Json;

Expand Down Expand Up @@ -203,8 +204,17 @@ private async Task<List<DnsRecordCloudflare>> 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<ActionResult> AddDnsRecord(string zoneId, string name, string value)
{
value = NormalizeTXTValue(value);

var request = CreateRequest(HttpMethod.Post, string.Format(_createRecordUri, zoneId));

request.Content = new StringContent(
Expand Down Expand Up @@ -315,6 +325,7 @@ public async Task<ActionResult> DeleteRecord(DnsRecord request)

public async Task<ActionResult> DeleteRecord(DnsRecord request, bool requireSameValue)
{
request.RecordValue = NormalizeTXTValue(request.RecordValue);

if (string.IsNullOrEmpty(request.RecordName))
{
Expand Down

0 comments on commit 8322a58

Please sign in to comment.