Skip to content

Commit 2f68ef8

Browse files
authored
Remove quotes from MultipartReader boundary (#41308)
1 parent 323b898 commit 2f68ef8

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/Http/WebUtilities/src/MultipartReader.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Microsoft.Extensions.Primitives;
5+
using Microsoft.Net.Http.Headers;
56

67
namespace Microsoft.AspNetCore.WebUtilities;
78

@@ -61,6 +62,7 @@ public MultipartReader(string boundary, Stream stream, int bufferSize)
6162
throw new ArgumentOutOfRangeException(nameof(bufferSize), bufferSize, "Insufficient buffer space, the buffer must be larger than the boundary: " + boundary);
6263
}
6364
_stream = new BufferedReadStream(stream, bufferSize);
65+
boundary = HeaderUtilities.RemoveQuotes(new StringSegment(boundary)).ToString();
6466
_boundary = new MultipartBoundary(boundary, false);
6567
// This stream will drain any preamble data and remove the first boundary marker.
6668
// TODO: HeadersLengthLimit can't be modified until after the constructor.

src/Http/WebUtilities/test/MultipartReaderTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Microsoft.AspNetCore.WebUtilities;
1010
public class MultipartReaderTests
1111
{
1212
private const string Boundary = "9051914041544843365972754266";
13+
private const string BoundaryWithQuotes = @"""9051914041544843365972754266""";
1314
// Note that CRLF (\r\n) is required. You can't use multi-line C# strings here because the line breaks on Linux are just LF.
1415
private const string OnePartBody =
1516
"--9051914041544843365972754266\r\n" +
@@ -377,4 +378,15 @@ public async Task MultipartReader_ReadInvalidUtf8SurrogateHeader_ReplacementChar
377378

378379
Assert.Null(await reader.ReadNextSectionAsync());
379380
}
381+
382+
// MultiPartReader should strip any quotes from the boundary passed in instead of throwing an exception
383+
[Fact]
384+
public async Task MultipartReader_StripQuotesFromBoundary()
385+
{
386+
var stream = MakeStream(OnePartBody);
387+
var reader = new MultipartReader(BoundaryWithQuotes, stream);
388+
389+
var section = await reader.ReadNextSectionAsync();
390+
Assert.NotNull(section);
391+
}
380392
}

0 commit comments

Comments
 (0)