diff --git a/pkg/fuzz/component/path.go b/pkg/fuzz/component/path.go index b9aebd61af..a81955167a 100644 --- a/pkg/fuzz/component/path.go +++ b/pkg/fuzz/component/path.go @@ -7,6 +7,7 @@ import ( "github.com/projectdiscovery/nuclei/v3/pkg/fuzz/dataformat" "github.com/projectdiscovery/retryablehttp-go" + "github.com/projectdiscovery/utils/maps" urlutil "github.com/projectdiscovery/utils/url" ) @@ -81,7 +82,7 @@ func (q *Path) Delete(key string) error { // Rebuild returns a new request with the // component rebuilt func (q *Path) Rebuild() (*retryablehttp.Request, error) { - originalValues := make(map[string]interface{}) + originalValues := mapsutil.Map[string, any]{} splitted := strings.Split(q.req.URL.Path, "/") for i := range splitted { pathTillNow := strings.Join(splitted[:i+1], "/") @@ -95,8 +96,22 @@ func (q *Path) Rebuild() (*retryablehttp.Request, error) { lengthSplitted := len(q.value.parsed.Map) for i := lengthSplitted; i > 0; i-- { key := strconv.Itoa(i) - original := originalValues[key].(string) - new := q.value.parsed.Map[key].(string) + + original, ok := originalValues.GetOrDefault(key, "").(string) + if !ok { + continue + } + + new, ok := q.value.parsed.Map.GetOrDefault(key, "").(string) + if !ok { + continue + } + + if new == original { + // no need to replace + continue + } + originalPath = strings.Replace(originalPath, original, new, 1) } diff --git a/pkg/fuzz/component/value.go b/pkg/fuzz/component/value.go index ad2044cf1b..030c5194bf 100644 --- a/pkg/fuzz/component/value.go +++ b/pkg/fuzz/component/value.go @@ -73,12 +73,22 @@ func (v *Value) SetParsed(data dataformat.KV, dataFormat string) { // SetParsedValue sets the parsed value for a key // in the parsed map -func (v *Value) SetParsedValue(key string, value string) bool { +func (v *Value) SetParsedValue(key, value string) bool { + if key == "" { + return false + } + origValue := v.parsed.Get(key) if origValue == nil { v.parsed.Set(key, value) return true } + + // TODO(dwisiswant0): I'm sure that this can be simplified because + // `dataformat.KV.*` is a type of `mapsutil.*` where the value is `any`. So, + // it looks like we won't type conversion here or even have its own methods + // inside `dataformat.KV`. + // If the value is a list, append to it // otherwise replace it switch v := origValue.(type) { diff --git a/pkg/fuzz/dataformat/kv.go b/pkg/fuzz/dataformat/kv.go index 72bd0da62e..3036a1c76c 100644 --- a/pkg/fuzz/dataformat/kv.go +++ b/pkg/fuzz/dataformat/kv.go @@ -13,7 +13,7 @@ import ( // if it's not important/significant (ex: json,xml) we use map // this also allows us to iteratively implement ordered map type KV struct { - Map map[string]interface{} + Map mapsutil.Map[string, any] OrderedMap *mapsutil.OrderedMap[string, any] }