Skip to content

fix: guard against goroutine leaks, url injection, and missing timeouts#11

Merged
enowdev merged 1 commit into
enowdev:mainfrom
Erzambayu:feat/skill-list-remove-update
Jul 10, 2026
Merged

fix: guard against goroutine leaks, url injection, and missing timeouts#11
enowdev merged 1 commit into
enowdev:mainfrom
Erzambayu:feat/skill-list-remove-update

Conversation

@Erzambayu

Copy link
Copy Markdown
Contributor

Summary

Multiple hardening fixes found during codebase audit.

Changes

Goroutine leak prevention

  • core/sync/presence.go — All Presence() calls now use context.WithTimeout(10s) instead of bare context.Background(). Previously a network hang in the presence heartbeat would leak goroutines indefinitely.

URL path injection

  • core/sync/sync.goUserByName() now escapes the username with url.PathEscape() before appending to the URL path. Special characters in usernames (/, ?, #) could corrupt the request path.

Missing HTTP client timeout

  • core/mitm/server.go — Replaced http.DefaultClient (no timeout) with a dedicated gatewayClient (5min timeout) in the intercept path, matching the existing passthroughClient pattern.

Full-sync dedup optimization

  • core/sync/items.go + core/sync/sync.go — Pre-built O(1) dedup lookup maps for full-sync pulls to avoid scanning the entire store per item (O(n²) at 1300+ accounts).

Data race fix

  • server/handlers/api_debug.go — Added sync.Mutex to serialize proc.Percent() and proc.MemoryInfo() calls. Previously concurrent polling from multiple browser tabs caused a data race producing wildly inflated cpu_percent values.

Test plan

  • go build ./... passes
  • go test ./core/sync/... ./core/mitm/... ./server/handlers/... passes
  • go test -race -run TestDebugConcurrentAccess ./server/handlers/... passes (no data race)

- core/sync/presence.go: use context.WithTimeout(10s) for all
  Presence() calls to prevent goroutine leaks on network hang
- core/sync/sync.go: url.PathEscape user input in UserByName
  to prevent path corruption with special characters
- core/mitm/server.go: replace http.DefaultClient with
  gatewayClient (5min timeout) in intercept path, matching
  the passthroughClient pattern
- core/sync/items.go + sync.go: O(1) dedup lookup maps for
  full-sync pull to avoid O(n^2) store scans at scale
- server/handlers/api_debug.go: serialize proc access with
  mutex to prevent data race in concurrent Percent() calls
@enowdev enowdev merged commit 4419930 into enowdev:main Jul 10, 2026
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.

2 participants