mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2026-02-04 09:43:13 +08:00
`hasMatchers` was not nil-safe when iterating over the slice of operators. Check if the operator is nil before accessing `*operators.Operators.Matchers` to prevent a panic when a protocol implementation returns a slice containing a nil element. This can happen when a request has no local matchers/extractors but is processed in a flow where global matchers are present. Fixes #6738. Signed-off-by: Dwi Siswanto <git@dw1.io>
41 lines
736 B
Go
41 lines
736 B
Go
package flow
|
|
|
|
import "github.com/projectdiscovery/nuclei/v3/pkg/operators"
|
|
|
|
// Checks if template has matchers
|
|
func hasMatchers(all []*operators.Operators) bool {
|
|
for _, operator := range all {
|
|
if operator != nil && len(operator.Matchers) > 0 {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// hasOperators checks if template has operators (i.e matchers/extractors)
|
|
func hasOperators(all []*operators.Operators) bool {
|
|
for _, operator := range all {
|
|
if operator != nil {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func flatten(v interface{}) interface{} {
|
|
switch v := v.(type) {
|
|
case []interface{}:
|
|
if len(v) == 1 {
|
|
return v[0]
|
|
}
|
|
return v
|
|
case []string:
|
|
if len(v) == 1 {
|
|
return v[0]
|
|
}
|
|
return v
|
|
default:
|
|
return v
|
|
}
|
|
}
|