Skip to content

Commit

Permalink
use stringsutil.HasPrefixAnyI
Browse files Browse the repository at this point in the history
  • Loading branch information
dogancanbakir committed Aug 28, 2023
1 parent 494dacc commit d720d4e
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions v2/pkg/protocols/common/protocolstate/headless.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

0 comments on commit d720d4e

Please sign in to comment.