From efca11e51c58bcc576543bcaaaec97bf14fc4396 Mon Sep 17 00:00:00 2001 From: ditatompel Date: Thu, 9 May 2024 20:44:49 +0700 Subject: [PATCH] Make nettype and protocol query more strict It will return error if nettype and protocol query string value is wrong --- internal/repo/monero.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/repo/monero.go b/internal/repo/monero.go index 30e1229..959fe12 100644 --- a/internal/repo/monero.go +++ b/internal/repo/monero.go @@ -108,10 +108,17 @@ func (repo *MoneroRepo) Nodes(q MoneroQueryParams) (MoneroNodes, error) { queryParams = append(queryParams, "%"+q.Host+"%") } if q.NetType != "any" { + if q.NetType != "mainnet" && q.NetType != "stagenet" && q.NetType != "testnet" { + return MoneroNodes{}, errors.New("Invalid nettype, must be one of 'mainnet', 'stagenet', 'testnet' or 'any'") + } whereQueries = append(whereQueries, "nettype = ?") queryParams = append(queryParams, q.NetType) } if q.Protocol != "any" { + allowedProtocols := []string{"tor", "http", "https"} + if !slices.Contains(allowedProtocols, q.Protocol) { + return MoneroNodes{}, errors.New("Invalid protocol, must be one of '" + strings.Join(allowedProtocols, "', '") + "' or 'any'") + } if q.Protocol == "tor" { whereQueries = append(whereQueries, "is_tor = ?") queryParams = append(queryParams, 1)