| package common |
|
|
| import ( |
| "fmt" |
| "net/url" |
| "strings" |
|
|
| "github.com/QuantumNous/new-api/constant" |
| ) |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| func ValidateRedirectURL(rawURL string) error { |
| |
| parsedURL, err := url.Parse(rawURL) |
| if err != nil { |
| return fmt.Errorf("invalid URL format: %s", err.Error()) |
| } |
|
|
| if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" { |
| return fmt.Errorf("invalid URL scheme: only http and https are allowed") |
| } |
|
|
| domain := strings.ToLower(parsedURL.Hostname()) |
|
|
| for _, trustedDomain := range constant.TrustedRedirectDomains { |
| if domain == trustedDomain || strings.HasSuffix(domain, "."+trustedDomain) { |
| return nil |
| } |
| } |
|
|
| return fmt.Errorf("domain %s is not in the trusted domains list", domain) |
| } |
|
|