1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 05:40:11 +01:00

Check if canonical url prefix is valid

This commit is contained in:
koplas 2025-04-03 14:41:14 +02:00
parent 2f599ab017
commit 91b5b4543e
No known key found for this signature in database

View file

@ -11,6 +11,7 @@ package main
import (
"fmt"
"io"
"net/url"
"os"
"strings"
@ -262,6 +263,14 @@ func loadConfig() (*config, error) {
if cfg.CanonicalURLPrefix == "" {
cfg.CanonicalURLPrefix = "https://" + os.Getenv("SERVER_NAME")
}
// Check if canonical url prefix is invalid
parsedURL, err := url.ParseRequestURI(cfg.CanonicalURLPrefix)
if err != nil {
return nil, err
}
if parsedURL.Scheme != "https" && parsedURL.Scheme != "http" {
return nil, fmt.Errorf("invalid canonical URL: %q", cfg.CanonicalURLPrefix)
}
if cfg.TLPs == nil {
cfg.TLPs = []tlp{tlpCSAF, tlpWhite, tlpGreen, tlpAmber, tlpRed}