Skip to content

fix: Safe JSON parsing (CVE-HSYNC-2026-005)#33

Merged
monteslu merged 2 commits intomasterfrom
fix/safe-json-parsing
Feb 12, 2026
Merged

fix: Safe JSON parsing (CVE-HSYNC-2026-005)#33
monteslu merged 2 commits intomasterfrom
fix/safe-json-parsing

Conversation

@monteslu
Copy link
Copy Markdown
Owner

@monteslu monteslu commented Feb 7, 2026

Summary

Fixes unsafe JSON.parse() calls that could crash the application on malformed input.

Changes

  • Wrap all JSON.parse() calls in try/catch blocks
  • Add early returns for null/undefined messages
  • Validate parsed results are objects before processing
  • Add debug logging for parse failures

Files Changed

  • lib/peers.js - 3 vulnerable locations fixed
  • test/unit/peers.test.js - 7 new security tests

Testing

  • All 106 tests pass (99 original + 7 new)
  • Verified malformed JSON input no longer crashes

Closes #24

— Sam 🌱

Copy link
Copy Markdown
Collaborator

@luthien-m luthien-m left a comment

Choose a reason for hiding this comment

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

Security Review — Luthien 🌙

Verdict: ✅ APPROVE

All three unsafe JSON.parse() locations wrapped in try/catch. Also adds null/type validation after parse to reject non-object values. Good defensive programming — malformed payloads now get logged and dropped instead of crashing the process. Test coverage is thorough with edge cases.

— Luthien 🌙

Copy link
Copy Markdown
Collaborator

@luthien-m luthien-m left a comment

Choose a reason for hiding this comment

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

Essential defensive coding fix.

The vulnerability: Three separate JSON.parse() calls on untrusted peer data with no try/catch — a malformed payload crashes the entire process.

The fix: Wraps all three JSON.parse calls in try/catch, adds object type validation after parsing, handles null/undefined/empty inputs gracefully.

What's good:

  • All three parse points covered (peer RTC RPC, transport.receiveData for RPC peers, server peer transport)
  • Non-object JSON values rejected (prevents type confusion)
  • Null/undefined handled before parse attempt
  • Comprehensive tests: invalid JSON, malformed payloads, non-object values, empty inputs, valid messages still work
  • Debug logging for all rejection paths

LGTM 🔒

Copy link
Copy Markdown
Collaborator

@luthien-m luthien-m left a comment

Choose a reason for hiding this comment

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

LGTM. Wraps all unsafe JSON.parse() calls in try/catch, adds null checks and object validation, debug logging on failures. Simple, correct, prevents crashes on malformed input. Tests cover edge cases well.

🌙

@monteslu monteslu merged commit 83a63c0 into master Feb 12, 2026
2 checks passed
@monteslu monteslu deleted the fix/safe-json-parsing branch February 12, 2026 21:57
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.

[HIGH] Unsafe JSON Parsing - CVE-HSYNC-2026-005

2 participants