mirror of
https://github.com/joohoi/acme-dns.git
synced 2024-12-22 15:53:44 +07:00
relax subdomain validation from UUID to actual subdomain (#243)
This commit is contained in:
parent
d573f771a8
commit
9c6ca258e1
@ -5,6 +5,8 @@ import (
|
|||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getValidUsername(u string) (uuid.UUID, error) {
|
func getValidUsername(u string) (uuid.UUID, error) {
|
||||||
@ -25,13 +27,12 @@ func validKey(k string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validSubdomain(s string) bool {
|
func validSubdomain(s string) bool {
|
||||||
_, err := uuid.Parse(s)
|
// URL safe base64 alphabet without padding as defined in ACME
|
||||||
if err == nil {
|
RegExp := regexp.MustCompile("^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$")
|
||||||
return true
|
return RegExp.MatchString(s)
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func validTXT(s string) bool {
|
func validTXT(s string) bool {
|
||||||
sn := sanitizeString(s)
|
sn := sanitizeString(s)
|
||||||
if utf8.RuneCountInString(s) == 43 && utf8.RuneCountInString(sn) == 43 {
|
if utf8.RuneCountInString(s) == 43 && utf8.RuneCountInString(sn) == 43 {
|
||||||
|
@ -55,7 +55,9 @@ func TestGetValidSubdomain(t *testing.T) {
|
|||||||
output bool
|
output bool
|
||||||
}{
|
}{
|
||||||
{"a097455b-52cc-4569-90c8-7a4b97c6eba8", true},
|
{"a097455b-52cc-4569-90c8-7a4b97c6eba8", true},
|
||||||
{"a-97455b-52cc-4569-90c8-7a4b97c6eba8", false},
|
{"a-97455b-52cc-4569-90c8-7a4b97c6eba8", true},
|
||||||
|
{"foo.example.com", false},
|
||||||
|
{"foo-example-com", true},
|
||||||
{"", false},
|
{"", false},
|
||||||
{"&!#!25123!%!'%", false},
|
{"&!#!25123!%!'%", false},
|
||||||
} {
|
} {
|
||||||
|
Loading…
Reference in New Issue
Block a user