Fix validation for ACL policy rules ports (#938)

This commit is contained in:
Givi Khojanashvili 2023-06-07 10:57:43 +04:00 committed by GitHub
parent 9460c4a91e
commit 803bbe0fff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ package http
import (
"encoding/json"
"net/http"
"strconv"
"github.com/gorilla/mux"
"github.com/rs/xid"
@ -175,8 +176,13 @@ func (h *Policies) savePolicy(
}
if r.Ports != nil && len(*r.Ports) != 0 {
ports := *r.Ports
pr.Ports = ports[:]
for _, v := range *r.Ports {
if port, err := strconv.Atoi(v); err != nil || port < 1 || port > 65535 {
util.WriteError(status.Errorf(status.InvalidArgument, "valid port value is in 1..65535 range"), w)
return
}
pr.Ports = append(pr.Ports, v)
}
}
// validate policy object