fix(fuzz): use OrderedMap for path segments to ensure deterministic iteration#6871
fix(fuzz): use OrderedMap for path segments to ensure deterministic iteration#6871Rhan2020 wants to merge 1 commit intoprojectdiscovery:devfrom
Conversation
…teration
Replace plain map[string]interface{} with mapsutil.OrderedMap in
Path.Parse() to preserve insertion order of path segments. Go maps
have non-deterministic iteration order, which caused the fuzzing
engine to randomly skip path segments (particularly numeric ones
like '55' in /user/55/profile).
Changes:
- Use mapsutil.NewOrderedMap and dataformat.KVOrderedMap in Parse(),
matching the pattern used by the Cookie component
- Update Rebuild() to use KV.Get() instead of direct .Map access
- Add TestPathComponent_DeterministicIteration regression test
Fixes #6398
WalkthroughThis pull request fixes a bug in path-based fuzzing where numeric path segments were being skipped during template fuzzing. The fix replaces a plain map with an ordered map to ensure deterministic iteration order of path segments, preventing non-deterministic behavior that caused segments to be randomly omitted from fuzzing operations. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi, thanks for your interest in contributing! Just a heads up, we ask contributors to work on 1 active issue at a time (see). Also, we welcome AI-assisted development, but submissions must be complete, tested, and ready to merge. Please also make sure to fill out the PR template with proof that your changes work. We're closing this PR along with your other open submissions. Once you're ready, feel free to pick one issue to focus on and resubmit; we'd be happy to review it. Appreciate your understanding! |
Summary
Fix non-deterministic path-based fuzzing that causes path segments (especially numeric ones like
55in/user/55/profile) to be randomly skipped.Fixes #6398
Root Cause
Path.Parse()stores path segments in a plain Gomap[string]interface{}. Since Go maps have non-deterministic iteration order,Path.Iterate()yields segments in random order, causing the fuzzing engine to sometimes skip segments.Fix
map[string]interface{}withmapsutil.OrderedMapinPath.Parse(), matching the pattern already used by theCookiecomponentdataformat.KVOrderedMap()instead ofdataformat.KVMap()to preserve insertion orderPath.Rebuild()to useKV.Get()instead of direct.Map.GetOrDefault()access (which would be nil with OrderedMap)TestPathComponent_DeterministicIterationregression test that runs 100 iterations to verify stable orderingChanges
2 files, minimal diff:
pkg/fuzz/component/path.go— 19 lines changedpkg/fuzz/component/path_test.go— 26 lines addedTesting
All existing tests pass, plus the new deterministic iteration test:
Full fuzz package suite also passes:
go test ./pkg/fuzz/... ✅Checklist
devbranchgo vet,go test ./pkg/fuzz/...)Summary by CodeRabbit
Release Notes
Bug Fixes
Tests