The vulnerability was due to improper sanitization of input variables used in constructing PowerShell commands. The core flawed sanitization was in internal/dnshelper.SanitiseString (original name) and consequently in internal/dnshelper.SanitiseTFInput which used it. These functions failed to neutralize special characters effectively for a PowerShell context.
Functions like internal/dnshelper.NewDNSRecordFromResource and internal/dnshelper.(*Record).Update consumed this insufficiently sanitized input to populate record data.
Subsequently, methods internal/dnshelper.(*Record).addRecordData and internal/dnshelper.(*Record).removeRecordData constructed PowerShell command strings by interpolating this potentially malicious data, in some cases without appropriate quoting (e.g., TXT records in addRecordData, and recordData in removeRecordData), leading to a command injection vulnerability.
The provider functions (resourceDNSRecordCreate, resourceDNSRecordUpdate, resourceDNSRecordDelete) in internal/provider/resource_win_dns_record.go served as the entry points, taking user-controlled data from Terraform configurations and passing it into this vulnerable processing chain.
The patch addresses this by:
- Introducing a more robust
SanitizeInputString function in internal/dnshelper/dnshelper.go which uses a regex for most record types and specific escaping (escapePowerShellInput) for TXT records.
- Modifying
SanitiseTFInput to use this new SanitizeInputString.
- Updating
NewDNSRecordFromResource and (*Record).Update in internal/dnshelper/dns.go to use the new sanitization logic and return errors if sanitization fails.
- Adding explicit quoting for
recordData in (*Record).addRecordData (for TXT records) and (*Record).removeRecordData in internal/dnshelper/dns.go.
- Propagating error handling for sanitization failures up to the provider functions in .