use stringsutil.HasPrefixAnyI

This commit is contained in:
Doğan Can Bakır 2023-08-28 08:15:30 +00:00
parent 494dacc671
commit d720d4ec8d

View File

@ -31,7 +31,7 @@ func ValidateNFailRequest(page *rod.Page, e *proto.FetchRequestPaused) error {
}
// validate potential invalid schemes
// javascript protocol is allowed for xss fuzzing
if HasPrefixAnyI(normalized, "ftp:", "externalfile:", "chrome:", "chrome-extension:") {
if stringsutil.HasPrefixAnyI(normalized, "ftp:", "externalfile:", "chrome:", "chrome-extension:") {
return multierr.Combine(FailWithReason(page, e), ErrURLDenied.Msgf(reqURL, "protocol blocked by network policy"))
}
if !isValidHost(reqURL) {
@ -77,14 +77,3 @@ func isValidHost(targetUrl string) bool {
_, ok := networkPolicy.ValidateHost(targetUrl)
return ok
}
// HasPrefixAnyI checks if the string has any of the prefixes
// TODO: replace with stringsutil.HasPrefixAnyI after implementation
func HasPrefixAnyI(s string, prefixes ...string) bool {
for _, prefix := range prefixes {
if stringsutil.HasPrefixI(s, prefix) {
return true
}
}
return false
}