File tree Expand file tree Collapse file tree
src/ModelContextProtocol.Core/Protocol
tests/ModelContextProtocol.Tests/Client Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -126,7 +126,8 @@ public static class McpHeaderEncoder
126126
127127 // Check for Base64 wrapper. The spec requires the sentinel markers to be
128128 // case-sensitive and exactly lowercase per SEP-2243.
129- if ( headerValue . StartsWith ( Base64Prefix , StringComparison . Ordinal ) &&
129+ if ( headerValue . Length >= Base64Prefix . Length + Base64Suffix . Length &&
130+ headerValue . StartsWith ( Base64Prefix , StringComparison . Ordinal ) &&
130131 headerValue . EndsWith ( Base64Suffix , StringComparison . Ordinal ) )
131132 {
132133 var base64Content = headerValue . Substring (
Original file line number Diff line number Diff line change @@ -104,6 +104,16 @@ public void DecodeValue_ValidBase64_Decodes()
104104 Assert . Equal ( "Hello" , result ) ;
105105 }
106106
107+ [ Fact ]
108+ public void DecodeValue_DegenerateWrapper_ReturnsLiteralValue ( )
109+ {
110+ // "=?base64?=" matches both the prefix "=?base64?" and the suffix "?=" because they
111+ // overlap on the shared '?', but it is too short to contain any base64 content. It must be
112+ // returned as-is rather than throwing when the wrapper is stripped.
113+ var result = McpHeaderEncoder . DecodeValue ( "=?base64?=" ) ;
114+ Assert . Equal ( "=?base64?=" , result ) ;
115+ }
116+
107117 [ Fact ]
108118 public void DecodeValue_CaseSensitivePrefix_ReturnsLiteralValue ( )
109119 {
You can’t perform that action at this time.
0 commit comments