netbirdio/netbird · error
TTL cannot be negative
Error message
TTL cannot be negative
What it means
Validate() rejects a negative TTL. TTL is copied verbatim from api.DNSRecordRequest.Ttl, and zero is explicitly allowed (it means "use default"), so only values below zero trigger this. There is no upper-bound check here.
Source
Thrown at management/internals/modules/zones/records/record.go:92
switch r.Type {
case RecordTypeA:
if err := validateIPv4(r.Content); err != nil {
return err
}
case RecordTypeAAAA:
if err := validateIPv6(r.Content); err != nil {
return err
}
case RecordTypeCNAME:
if !domain.IsValidDomainNoWildcard(r.Content) {
return errors.New("invalid CNAME target format")
}
default:
return errors.New("invalid record type, must be A, AAAA, or CNAME")
}
if r.TTL < 0 {
return errors.New("TTL cannot be negative")
}
return nil
}
func (r *Record) EventMeta(zoneID, zoneName string) map[string]any {
return map[string]any{
"name": r.Name,
"type": string(r.Type),
"content": r.Content,
"ttl": r.TTL,
"zone_id": zoneID,
"zone_name": zoneName,
}
}
func validateIPv4(content string) error {
if content == "" {View on GitHub (pinned to 93e97f4bf1)
Solutions
- Send a TTL of 0 (default) or a positive number of seconds.
- If computing TTL dynamically, clamp it: ttl = max(0, computed).
- Validate at the client boundary that the TTL field is >= 0 before issuing the request.
Example fix
// before
{"name": "api", "type": "A", "content": "192.0.2.1", "ttl": -300}
// after
{"name": "api", "type": "A", "content": "192.0.2.1", "ttl": 300} Defensive patterns
Strategy: validation
Validate before calling
if req.Ttl < 0 {
return fmt.Errorf("ttl must be >= 0, got %d", req.Ttl)
} Try / catch
if err := rec.Validate(); err != nil {
return respondBadRequest(err)
} Prevention
- Clamp computed TTLs with max(0, v) before sending.
- Use 0 to mean default rather than a negative sentinel.
When it happens
Trigger: A record body with "ttl": -1; a client computing TTL as a delta (e.g. expiry minus now) that goes negative when the expiry is in the past; integer underflow in generated payloads.
Common situations: Scripts deriving TTL from timestamps; form fields accepting negative numbers; negative values used as a "disable" sentinel by client convention but rejected by the server.
Related errors
- record name is required
- invalid record name format
- record type is required
- invalid CNAME target format
- invalid record type, must be A, AAAA, or CNAME
AI-assisted analysis of netbirdio/netbird@93e97f4bf1 (2026-08-16).
Data as JSON: /api/errors/58e71f3efaf91c84.
Report an issue: GitHub.