nuclei/pkg/protocols/http/request_condition.go
tongjicoder 3be29abfc9 refactor: use slices.Contains to simplify code
Signed-off-by: tongjicoder <tongjicoder@icloud.com>
2025-05-27 17:16:26 +08:00

38 lines
874 B
Go

package http
import (
"regexp"
"slices"
)
var (
// Determines if request condition are needed by detecting the pattern _xxx
reRequestCondition = regexp.MustCompile(`(?m)_\d+`)
)
// NeedsRequestCondition determines if request condition should be enabled
func (request *Request) NeedsRequestCondition() bool {
for _, matcher := range request.Matchers {
if checkRequestConditionExpressions(matcher.DSL...) {
return true
}
if checkRequestConditionExpressions(matcher.Part) {
return true
}
}
for _, extractor := range request.Extractors {
if checkRequestConditionExpressions(extractor.DSL...) {
return true
}
if checkRequestConditionExpressions(extractor.Part) {
return true
}
}
return false
}
func checkRequestConditionExpressions(expressions ...string) bool {
return slices.ContainsFunc(expressions, reRequestCondition.MatchString)
}