From a7e764391ce4e520c9f48eaa20ab002244473911 Mon Sep 17 00:00:00 2001 From: Vincent Hagen Date: Mon, 11 Dec 2023 02:47:44 +0100 Subject: [PATCH] TRANSIP: Fix TXT quoting (#2708) Co-authored-by: Tom Limoncelli --- integrationTest/integration_test.go | 3 ++- pkg/rejectif/txt.go | 9 +++++++++ providers/transip/auditrecords.go | 4 ++++ providers/transip/transipProvider.go | 5 ++--- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/integrationTest/integration_test.go b/integrationTest/integration_test.go index 2c1725c27..fc69712c6 100644 --- a/integrationTest/integration_test.go +++ b/integrationTest/integration_test.go @@ -1126,7 +1126,8 @@ func makeTests(t *testing.T) []*TestGroup { tc("TXT with semicolon ws", txt("foosc2", `wssemi ; colon`)), tc("TXT interior ws", txt("foosp", "with spaces")), - tc("TXT trailing ws", txt("foows1", "with space at end ")), + tc("TXT leading ws", txt("foowsb", " leadingspace")), + tc("TXT trailing ws", txt("foows1", "trailingws ")), // Vultr syntax-checks TXT records with SPF contents. tc("Create a TXT/SPF", txt("foo", "v=spf1 ip4:99.99.99.99 -all")), diff --git a/pkg/rejectif/txt.go b/pkg/rejectif/txt.go index 2503f158f..9e4bf161f 100644 --- a/pkg/rejectif/txt.go +++ b/pkg/rejectif/txt.go @@ -17,6 +17,15 @@ func TxtHasBackslash(rc *models.RecordConfig) error { return nil } +// TxtStartsOrEndsWithSpaces audits TXT records that starts or ends with spaces +func TxtStartsOrEndsWithSpaces(rc *models.RecordConfig) error { + txt := rc.GetTargetTXTJoined() + if len(txt) > 0 && (txt[0] == ' ' || txt[len(txt)-1] == ' ') { + return fmt.Errorf("txtstring starts or ends with spaces") + } + return nil +} + // TxtHasBackticks audits TXT records for strings that contain backticks. func TxtHasBackticks(rc *models.RecordConfig) error { if strings.Contains(rc.GetTargetTXTJoined(), "`") { diff --git a/providers/transip/auditrecords.go b/providers/transip/auditrecords.go index 8004671b1..4836b70af 100644 --- a/providers/transip/auditrecords.go +++ b/providers/transip/auditrecords.go @@ -19,5 +19,9 @@ func AuditRecords(records []*models.RecordConfig) []error { a.Add("TXT", rejectif.TxtHasBackslash) // Last verified 2023-12-04 + a.Add("TXT", rejectif.TxtStartsOrEndsWithSpaces) // Last verified 2023-12-10 + + a.Add("TXT", rejectif.TxtIsEmpty) // Last verified 2023-12-10 + return a.Audit(records) } diff --git a/providers/transip/transipProvider.go b/providers/transip/transipProvider.go index 021d0eb8f..51b470678 100644 --- a/providers/transip/transipProvider.go +++ b/providers/transip/transipProvider.go @@ -8,7 +8,6 @@ import ( "github.com/StackExchange/dnscontrol/v4/models" "github.com/StackExchange/dnscontrol/v4/pkg/diff2" - "github.com/StackExchange/dnscontrol/v4/pkg/txtutil" "github.com/StackExchange/dnscontrol/v4/providers" "github.com/transip/gotransip/v6" "github.com/transip/gotransip/v6/domain" @@ -310,7 +309,7 @@ func recordToNative(config *models.RecordConfig, useOriginal bool) (domain.DNSEn Name: config.Name, Expire: int(config.TTL), Type: config.Type, - Content: config.GetTargetCombinedFunc(txtutil.EncodeQuoted), + Content: config.GetTargetCombinedFunc(nil), }, nil } @@ -322,7 +321,7 @@ func nativeToRecord(entry domain.DNSEntry, origin string) (*models.RecordConfig, Original: entry, } rc.SetLabel(entry.Name, origin) - if err := rc.PopulateFromStringFunc(entry.Type, entry.Content, origin, txtutil.ParseQuoted); err != nil { + if err := rc.PopulateFromStringFunc(entry.Type, entry.Content, origin, nil); err != nil { return nil, fmt.Errorf("unparsable record received from TransIP: %w", err) }