Reject origins with trailing empty port in validator

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-14 15:58:44 +04:00
parent 8ec434d67e
commit abd565c96a

View File

@@ -18,6 +18,7 @@ import (
"net/url" "net/url"
"regexp" "regexp"
"slices" "slices"
"strings"
"go.probo.inc/probo/pkg/gid" "go.probo.inc/probo/pkg/gid"
) )
@@ -160,7 +161,7 @@ func Origin() ValidatorFunc {
return newValidationError(ErrorCodeInvalidFormat, "must be a valid origin (e.g. https://example.com)") return newValidationError(ErrorCodeInvalidFormat, "must be a valid origin (e.g. https://example.com)")
} }
if parsedURL.Host == "" || parsedURL.Hostname() == "" { if parsedURL.Host == "" || parsedURL.Hostname() == "" || strings.HasSuffix(parsedURL.Host, ":") {
return newValidationError(ErrorCodeInvalidFormat, "must be a valid origin (e.g. https://example.com)") return newValidationError(ErrorCodeInvalidFormat, "must be a valid origin (e.g. https://example.com)")
} }