Skip to content

fix: validate array length to prevent RangeError crash (CVE-2026-97057) - #67

Open
DingWeizhe wants to merge 1 commit into
NodeRedis:masterfrom
DingWeizhe:fix/array-length-validation
Open

DingWeizhe wants to merge 1 commit into
NodeRedis:masterfrom
DingWeizhe:fix/array-length-validation

Conversation

@DingWeizhe

Copy link
Copy Markdown

Summary

Fixes CVE-2026-97057 (refs #65, #47).

parseArray passed the declared length of a RESP array (*<n>\r\n) directly to new Array(length). When the length is greater than 2^32 - 1, this throws an uncaught RangeError: Invalid array length and crashes the Node.js process. A malicious or compromised Redis endpoint can trigger it with a single header such as *4294967296\r\n.

Changes

  • Reject array lengths above 2^32 - 1. The parser now reports a ParserError (Protocol error, invalid array length <n>) through returnFatalError and resets its buffer, the same way unknown reply type bytes are handled.
  • Negative lengths still return null, so the behavior for valid input is unchanged.

Tests

  • New test: *4294967296\r\n produces a ParserError, and the parser still parses replies afterwards.
  • New test: the upper bound *4294967295\r\n is still accepted.
  • Without the fix, the new test fails with RangeError: Invalid array length. With the fix, all 36 tests pass, standard lint passes, and coverage stays at 100%.

🤖 Generated with Claude Code

A RESP array header declaring more than 2^32 - 1 elements made
`new Array(length)` throw an uncaught RangeError, which crashes the
Node.js process. A malicious or compromised Redis endpoint could
trigger it.

Reject such lengths with a ParserError through returnFatalError, the
same way other protocol errors are handled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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