From d720d4ec8d2273e3f241a9065a13a77ad40abc6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fan=20Can=20Bak=C4=B1r?= Date: Mon, 28 Aug 2023 08:15:30 +0000 Subject: [PATCH] use stringsutil.HasPrefixAnyI --- v2/pkg/protocols/common/protocolstate/headless.go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/v2/pkg/protocols/common/protocolstate/headless.go b/v2/pkg/protocols/common/protocolstate/headless.go index 86cbb2511b..36689b3b8c 100644 --- a/v2/pkg/protocols/common/protocolstate/headless.go +++ b/v2/pkg/protocols/common/protocolstate/headless.go @@ -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 -}