fix: Allow tor address with subdomain #149

This commit is contained in:
Cristian Ditaputratama 2024-11-06 20:47:34 +07:00
parent 3f5c2b9905
commit f227371fa6
Signed by: ditatompel
GPG key ID: 31D3D06D77950979

View file

@ -296,10 +296,12 @@ func (r *moneroRepo) Add(protocol string, hostname string, port uint) error {
return nil return nil
} }
// Checks if a given hostname is a valid TOR v3 .onion address // validTorHostname shecks if a given hostname is a valid TOR v3 .onion address
// TOR v3 .onion addresses are 56 characters of base32 followed by ".onion" // with optional subdomain
//
// TOR v3 .onion addresses are 56 characters of `base32` followed by ".onion"
func validTorHostname(hostname string) bool { func validTorHostname(hostname string) bool {
return regexp.MustCompile(`^[a-z2-7]{56}\.onion$`).MatchString(hostname) return regexp.MustCompile(`^([a-z0-9-]+\.)*[a-z2-7]{56}\.onion$`).MatchString(hostname)
} }
func (r *moneroRepo) Delete(id uint) error { func (r *moneroRepo) Delete(id uint) error {