zrhoffman commented on a change in pull request #4107:
URL: https://github.com/apache/trafficcontrol/pull/4107#discussion_r432062045
##########
File path: traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
##########
@@ -106,7 +107,7 @@ func (staticDNSEntry TOStaticDNSEntry) Validate() error {
}
errs := validation.Errors{
- "host": validation.Validate(staticDNSEntry.Host,
validation.Required, is.DNSName),
+ "host": validation.Validate(staticDNSEntry.Host,
validation.Required,
validation.Match(regexp.MustCompile(`^([a-zA-Z0-9_@*]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*[\._]?$`))),
Review comment:
This regex looks identical to [the one used in
asaskevich/govalidator](https://github.com/asaskevich/govalidator/blob/7e6e9a9af9/patterns.go#L32)
but with `@` and `*` added to the first character class.
It matches all of our use cases but it also matches undesired ones as well:
* `*ubdomain.domain.com`, which violates [RFC
1034](https://tools.ietf.org/html/rfc1034#section-4.3.3)
* `@.domain.com`, which violates [RFC
1035](https://tools.ietf.org/html/rfc1035#page-35)
`@` should only be allowed if it is the entire entry, and `*` should only be
allowed in the form `*.<anydomain>` (including free-standing `*`).
This pattern should match all of our use cases. Feel free to use it:
```regex
^(@|((\*|([a-zA-Z0-9_][a-zA-Z0-9_-]{0,62}))(\.[a-zA-Z0-9_][a-zA-Z0-9_-]{0,62})*[._]?))$
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]