mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2024-11-17 01:17:37 +00:00
feat: Added TOR address validation #149
This commit is contained in:
parent
df161f831a
commit
3f5c2b9905
1 changed files with 9 additions and 2 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"log/slog"
|
||||
"math"
|
||||
"net"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -221,8 +222,8 @@ func (r *moneroRepo) Add(protocol string, hostname string, port uint) error {
|
|||
ipAddr = hostIp.String()
|
||||
ips = ip.SliceToString(hostIps)
|
||||
} else {
|
||||
if strings.HasPrefix(hostname, "http://") || strings.HasPrefix(hostname, "https://") {
|
||||
return errors.New("Don't start hostname with http:// or https://, just put your hostname")
|
||||
if !validTorHostname(hostname) {
|
||||
return errors.New("Invalid TOR v3 .onion hostname")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -295,6 +296,12 @@ func (r *moneroRepo) Add(protocol string, hostname string, port uint) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Checks if a given hostname is a valid TOR v3 .onion address
|
||||
// TOR v3 .onion addresses are 56 characters of base32 followed by ".onion"
|
||||
func validTorHostname(hostname string) bool {
|
||||
return regexp.MustCompile(`^[a-z2-7]{56}\.onion$`).MatchString(hostname)
|
||||
}
|
||||
|
||||
func (r *moneroRepo) Delete(id uint) error {
|
||||
if _, err := r.db.Exec(`DELETE FROM tbl_node WHERE id = ?`, id); err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue