Skip to content

fix: race in Diff mode crashes Hoverfly (GHSA-qrh4-p6v4-mrfg)#1227

Merged
tommysitu merged 1 commit into
masterfrom
fix/diff-mode-race-ghsa-qrh4-p6v4-mrfg
May 27, 2026
Merged

fix: race in Diff mode crashes Hoverfly (GHSA-qrh4-p6v4-mrfg)#1227
tommysitu merged 1 commit into
masterfrom
fix/diff-mode-race-ghsa-qrh4-p6v4-mrfg

Conversation

@tommysitu
Copy link
Copy Markdown
Member

Summary

  • Diff mode crashed with fatal error: concurrent map read and map write under concurrent proxy traffic because responsesDiff (in core/hoverfly.go) was a plain map with no synchronization. Trivially triggerable: any client with proxy access could send a handful of simultaneous requests and DoS the process. Reported as GHSA-qrh4-p6v4-mrfg.
  • Added a dedicated sync.RWMutex next to responsesDiff (mirroring the state.State pattern) and wrapped all four accessors: AddDiff / ClearDiff (write lock), GetDiff / GetFilteredDiff (read lock).
  • GetDiff now returns a deep snapshot so DiffHandler.convertToResponseDiffView can iterate the result after the lock is released without reintroducing the race.

Test plan

  • go test -race -count=1 -v -run 'Test_Hoverfly_AddDiff|Test_Hoverfly_Diff_ConcurrentAccess|Test_Hoverfly_processRequest_CanHandleResponseDiff' github.com/SpectoLabs/hoverfly/core — all green.
  • New Test_Hoverfly_Diff_ConcurrentAccess (32 writer goroutines × 64 readers × 1 clearer × 100 iterations each) — reliably trips Go's map-race check on pre-patch code; passes under -race with the patch (~110 ms).
  • go vet github.com/SpectoLabs/hoverfly/core — clean.
  • Optional manual repro: run the advisory's curl POC against a built binary in Diff mode and confirm the process stays alive.

🤖 Generated with Claude Code

Diff mode's responsesDiff map had no synchronization, so concurrent
proxy requests tripped Go's built-in concurrent-map check and crashed
the process with "fatal error: concurrent map read and map write".

Add a dedicated sync.RWMutex covering AddDiff, ClearDiff, GetDiff, and
GetFilteredDiff. GetDiff now returns a deep snapshot so DiffHandler can
iterate the result outside the lock without re-introducing the race.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@tommysitu tommysitu merged commit cb576ef into master May 27, 2026
4 checks passed
@tommysitu tommysitu deleted the fix/diff-mode-race-ghsa-qrh4-p6v4-mrfg branch May 27, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant