Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions pkg/fuzz/component/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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], "/")
Expand All @@ -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)
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/fuzz/component/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fuzz/dataformat/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down