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"
|
"log/slog"
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -221,8 +222,8 @@ func (r *moneroRepo) Add(protocol string, hostname string, port uint) error {
|
||||||
ipAddr = hostIp.String()
|
ipAddr = hostIp.String()
|
||||||
ips = ip.SliceToString(hostIps)
|
ips = ip.SliceToString(hostIps)
|
||||||
} else {
|
} else {
|
||||||
if strings.HasPrefix(hostname, "http://") || strings.HasPrefix(hostname, "https://") {
|
if !validTorHostname(hostname) {
|
||||||
return errors.New("Don't start hostname with http:// or https://, just put your 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
|
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 {
|
func (r *moneroRepo) Delete(id uint) error {
|
||||||
if _, err := r.db.Exec(`DELETE FROM tbl_node WHERE id = ?`, id); err != nil {
|
if _, err := r.db.Exec(`DELETE FROM tbl_node WHERE id = ?`, id); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue