Bounds check the DCEP OPEN label and protocol lengths - #1779
Merged
Merged
Conversation
DataChannelOpenMessage.Parse read the label and protocol lengths from the buffer and passed them to Encoding.UTF8.GetString without checking they fit within it. A DCEP OPEN message declaring a label longer than the data it carried threw an ArgumentException rather than the ApplicationException used to signal a malformed message, and the data channel silently failed to open. The label and protocol were also read from a fixed offset of 12 rather than relative to posn, as was the minimum length check. Every caller passes a posn of 0 so this was latent, but the function was wrong as written. Resolves #1778. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
| [Trait("Category", "unit")] | ||
| public class DataChannelOpenMessageUnitTest | ||
| { | ||
| private Microsoft.Extensions.Logging.ILogger logger = null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the DCEP OPEN parser bounds check reported in #1778.
Changes
DataChannelOpenMessage.Parsenow checks the label and protocol lengths against the space actually left in the buffer before using them:The lengths are summed as an
intso a pair that only overflows when combined is caught, and neither value can wrap.Malformed messages now surface as
ApplicationException, consistent with the rest of the parser, so they are handled by the recoverable-error path inRTCSctpTransport.DoReceiverather than the defence-in-depth catch below it.Also corrected two places where
posnwas ignored:buffer.Lengthagainst the fixed parameters length rather than the bytes remaining fromposn12instead ofposn + 12Every current caller passes
posn = 0, so this was latent rather than live, but it did not match the signature orWriteTo, which does honourposn.Tests
New
DataChannelOpenMessageUnitTestcovering:0xFFFFon a 12 byte buffer, the case from DCEP OPEN parser does not bounds check labelLength/protocolLength against the buffer #17780xFFFFposn, and aposnleaving too few bytesAll 7 pass, along with the 127 existing SCTP, WebRTC and data channel unit tests on net8.0.
Note on classification
#1778 arrived as a private security report. It is a genuine parser defect but not a vulnerability: reaching this code requires completing the DTLS handshake as the peer authenticated against the signalled fingerprint, and the only consequence is that the sender's own data channel does not open.
Encoding.UTF8.GetStringvalidates its arguments and throws before reading, so nothing is read past the buffer. The reasoning is recorded in the issue.🤖 Generated with Claude Code