Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/protocols/http/request_condition.go
2070 views
1
package http
2
3
import (
4
"regexp"
5
"slices"
6
)
7
8
var (
9
// Determines if request condition are needed by detecting the pattern _xxx
10
reRequestCondition = regexp.MustCompile(`(?m)_\d+`)
11
)
12
13
// NeedsRequestCondition determines if request condition should be enabled
14
func (request *Request) NeedsRequestCondition() bool {
15
for _, matcher := range request.Matchers {
16
if checkRequestConditionExpressions(matcher.DSL...) {
17
return true
18
}
19
if checkRequestConditionExpressions(matcher.Part) {
20
return true
21
}
22
}
23
for _, extractor := range request.Extractors {
24
if checkRequestConditionExpressions(extractor.DSL...) {
25
return true
26
}
27
if checkRequestConditionExpressions(extractor.Part) {
28
return true
29
}
30
}
31
32
return false
33
}
34
35
func checkRequestConditionExpressions(expressions ...string) bool {
36
return slices.ContainsFunc(expressions, reRequestCondition.MatchString)
37
}
38
39