Skip to content
Closed
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
19 changes: 13 additions & 6 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"
mapsutil "github.com/projectdiscovery/utils/maps"
urlutil "github.com/projectdiscovery/utils/url"
)

Expand Down Expand Up @@ -36,7 +37,8 @@ func (q *Path) Parse(req *retryablehttp.Request) (bool, error) {
q.value = NewValue("")

splitted := strings.Split(req.Path, "/")
values := make(map[string]interface{})
segments := mapsutil.NewOrderedMap[string, any]()
segmentIndex := 0
for i, segment := range splitted {
if segment == "" && i == 0 {
// Skip the first empty segment from leading "/"
Expand All @@ -47,10 +49,11 @@ func (q *Path) Parse(req *retryablehttp.Request) (bool, error) {
continue
}
// Use 1-based indexing and store individual segments
key := strconv.Itoa(len(values) + 1)
values[key] = segment
segmentIndex++
key := strconv.Itoa(segmentIndex)
segments.Set(key, segment)
}
q.value.SetParsed(dataformat.KVMap(values), "")
q.value.SetParsed(dataformat.KVOrderedMap(&segments), "")
return true, nil
}

Expand Down Expand Up @@ -109,8 +112,12 @@ func (q *Path) Rebuild() (*retryablehttp.Request, error) {

// Check if we have a replacement for this segment
key := strconv.Itoa(segmentIndex)
if newValue, exists := q.value.parsed.Map.GetOrDefault(key, "").(string); exists && newValue != "" {
rebuiltSegments = append(rebuiltSegments, newValue)
if val := q.value.parsed.Get(key); val != nil {
if newValue, ok := val.(string); ok && newValue != "" {
rebuiltSegments = append(rebuiltSegments, newValue)
} else {
rebuiltSegments = append(rebuiltSegments, originalSegment)
}
} else {
rebuiltSegments = append(rebuiltSegments, originalSegment)
}
Expand Down
26 changes: 26 additions & 0 deletions pkg/fuzz/component/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,32 @@ func TestURLComponent_NestedPaths(t *testing.T) {
}
}

func TestPathComponent_DeterministicIteration(t *testing.T) {
// Verify that path segments are always iterated in insertion order.
// Before the fix, a plain Go map caused non-deterministic iteration,
// which randomly skipped path segments during fuzzing.
for run := 0; run < 100; run++ {
path := NewPath()
req, err := retryablehttp.NewRequest(http.MethodGet, "https://example.com/user/55/profile", nil)
require.NoError(t, err)

found, err := path.Parse(req)
require.NoError(t, err)
require.True(t, found)

var keys []string
var values []string
err = path.Iterate(func(key string, value interface{}) error {
keys = append(keys, key)
values = append(values, value.(string))
return nil
})
require.NoError(t, err)
require.Equal(t, []string{"1", "2", "3"}, keys, "run %d: unexpected keys", run)
require.Equal(t, []string{"user", "55", "profile"}, values, "run %d: unexpected values", run)
}
}

func TestPathComponent_SQLInjection(t *testing.T) {
path := NewPath()
req, err := retryablehttp.NewRequest(http.MethodGet, "https://example.com/user/55/profile", nil)
Expand Down