Skip to content

Reject malformed Content-Length header values - #1951

Merged
Dirk Bäumer (dbaeumer) merged 2 commits into
microsoft:mainfrom
pradeep-ramola:fix/strict-content-length
Nov 30, 2026
Merged

Dirk Bäumer (dbaeumer) merged 2 commits into
microsoft:mainfrom
pradeep-ramola:fix/strict-content-length

Conversation

@pradeep-ramola

Copy link
Copy Markdown
Contributor

ReadableStreamMessageReader currently uses parseInt without validating the complete header value. Values such as 43junk, 43.0, +43, and 43e0 can therefore deliver a message as though the peer supplied a valid decimal byte length. Hexadecimal values are also accepted, and unsafe integers enter the partial-body read path.

Validate that the complete value contains decimal digits and represents a safe integer before using it for body framing. Keep the existing NaN diagnostic and accept ordinary decimal, zero-padded decimal, and header whitespace trimmed by the message buffer.

Tests cover eight invalid values (including negatives and an unsafe integer) and three valid values with the message split across chunks. The six non-negative malformed cases fail on unchanged main. This is a parser-correctness fix; no security exploit or impact is claimed.

Validation:

  • npm run compile:jsonrpc
  • npm --prefix jsonrpc run lint
  • npm --prefix jsonrpc run test:node (90 passing)
  • git diff --check

Browser and editor integration tests were not run.

Copilot AI balanced review requested due to automatic review settings November 22, 2026 07:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the change tightening JSON-RPC Content-Length validation.

No open issues 🎉

What changed in this PR

This PR tightens JSON-RPC message framing by rejecting Content-Length values that are not complete decimal strings representing non-negative safe integers.

Changes:

  • Parses lengths in base 10 and validates the entire header value before reading the body.
  • Preserves the existing NaN diagnostic and support for zero-padding and trimmed header whitespace.
  • Adds tests for eight malformed values and three valid formats, including chunked message delivery.
File Description
jsonrpc/​src/​node/​test/​messages.test.ts Adds malformed-length rejection and valid chunked-message tests.
jsonrpc/​src/​common/​messageReader.ts Validates decimal syntax and safe integer bounds before body framing.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 30, 2026 15:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the changes tightening JSON-RPC Content-Length validation.

No open issues 🎉

Review effort: Balanced

@dbaeumer
Dirk Bäumer (dbaeumer) merged commit 67f50bf into microsoft:main Nov 30, 2026
7 checks passed
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.

5 participants