mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-12-09 05:36:27 +08:00
ALIDNS: Add TXT record validation
This commit is contained in:
parent
77b8b53227
commit
51492f802c
3 changed files with 30 additions and 9 deletions
|
|
@ -18,6 +18,29 @@ func TxtHasBackslash(rc *models.RecordConfig) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// TxtHasUnpairedBackslash audits TXT records for strings that contain an odd number of consecutive backslashes.
|
||||
// Some providers strip single backslashes or convert odd consecutive backslashes to even.
|
||||
// e.g., "1back\slash" -> "1backslash", "3back\\\slash" -> "3back\\slash"
|
||||
func TxtHasUnpairedBackslash(rc *models.RecordConfig) error {
|
||||
txt := rc.GetTargetTXTJoined()
|
||||
i := 0
|
||||
for i < len(txt) {
|
||||
if txt[i] == '\\' {
|
||||
count := 0
|
||||
for i < len(txt) && txt[i] == '\\' {
|
||||
count++
|
||||
i++
|
||||
}
|
||||
if count%2 == 1 {
|
||||
return errors.New("txtstring contains unpaired backslash (odd count)")
|
||||
}
|
||||
} else {
|
||||
i++
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TxtHasBackticks audits TXT records for strings that contain backticks.
|
||||
func TxtHasBackticks(rc *models.RecordConfig) error {
|
||||
if strings.Contains(rc.GetTargetTXTJoined(), "`") {
|
||||
|
|
|
|||
|
|
@ -51,15 +51,10 @@ func (a *aliDnsDsp) createRecordset(records []*models.RecordConfig, domainName s
|
|||
req.Priority = requests.Integer(fmt.Sprintf("%d", recordToNativePriority(r)))
|
||||
}
|
||||
|
||||
fmt.Printf("DEBUG createRecordset: domain=%s, RR=%s, Type=%s, Value=%s, TTL=%s\n",
|
||||
req.DomainName, req.RR, req.Type, req.Value, req.TTL)
|
||||
|
||||
resp, err := a.client.AddDomainRecord(req)
|
||||
_, err := a.client.AddDomainRecord(req)
|
||||
if err != nil {
|
||||
fmt.Printf("DEBUG createRecordset error: %v\n", err)
|
||||
return err
|
||||
}
|
||||
fmt.Printf("DEBUG createRecordset success: RecordId=%s\n", resp.RecordId)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,5 +14,8 @@ func AuditRecords(records []*models.RecordConfig) []error {
|
|||
a.Add("MX", rejectif.MxNull) // Last verified at 2025-12-03
|
||||
a.Add("TXT", rejectif.TxtIsEmpty) // Last verified at 2025-12-03
|
||||
a.Add("TXT", rejectif.TxtLongerThan(512)) // Last verified at 2025-12-03: 511 bytes OK, 764 bytes failed
|
||||
a.Add("TXT", rejectif.TxtHasDoubleQuotes) // Last verified at 2025-12-03: Alibaba strips quotes
|
||||
a.Add("TXT", rejectif.TxtHasTrailingSpace) // Last verified at 2025-12-03: Alibaba strips trailing spaces
|
||||
a.Add("TXT", rejectif.TxtHasUnpairedBackslash) // Last verified at 2025-12-03: Alibaba mishandles odd backslashes
|
||||
return a.Audit(records)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue