Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 10 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,14 @@ 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 := originalValues.GetOrDefault(key, "").(string)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we guard here using fmt.Sprint(..), anyway if it's a string we will get the same value of .(string)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we guard here using fmt.Sprint(..) [...]

If the values are always strings (or not?), sticking with the type assertion might be preferable for performance & type safety reasons.

[...] anyway if it's a string we will get the same value of .(string)?

Since the type of map is any, we still need to do a type assertion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we should ensure that the assertion went correctly with:

a, ok := c.(string)
if !ok {
    continue 
}

what do you think?

new := q.value.parsed.Map.GetOrDefault(key, "").(string)
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