@@ -115,6 +115,14 @@ public async Task ReadFormAsync_SimpleData_ReturnsParsedFormCollection(bool buff
115
115
"\r \n " +
116
116
"Foo\r \n " ;
117
117
118
+ private const string InvalidContentDispositionValue = "form-data; name=\" description\" - filename=\" temp.html\" " ;
119
+
120
+ private const string MultipartFormFileInvalidContentDispositionValue = "--WebKitFormBoundary5pDRpGheQXaM8k3T\r \n " +
121
+ "Content-Disposition: " +
122
+ InvalidContentDispositionValue +
123
+ "\r \n " +
124
+ "\r \n " +
125
+ "Foo\r \n " ;
118
126
119
127
private const string MultipartFormWithField =
120
128
MultipartFormField +
@@ -137,6 +145,10 @@ public async Task ReadFormAsync_SimpleData_ReturnsParsedFormCollection(bool buff
137
145
MultipartFormFileSpecialCharacters +
138
146
MultipartFormEndWithSpecialCharacters ;
139
147
148
+ private const string MultipartFormWithInvalidContentDispositionValue =
149
+ MultipartFormFileInvalidContentDispositionValue +
150
+ MultipartFormEnd ;
151
+
140
152
[ Theory ]
141
153
[ InlineData ( true ) ]
142
154
[ InlineData ( false ) ]
@@ -489,6 +501,24 @@ public async Task ReadFormAsync_MultipartWithFieldAndMediumFile_ReturnsParsedFor
489
501
await responseFeature . CompleteAsync ( ) ;
490
502
}
491
503
504
+ [ Fact ]
505
+ public async Task ReadFormAsync_MultipartWithInvalidContentDisposition_Throw ( )
506
+ {
507
+ var formContent = Encoding . UTF8 . GetBytes ( MultipartFormWithInvalidContentDispositionValue ) ;
508
+ var context = new DefaultHttpContext ( ) ;
509
+ var responseFeature = new FakeResponseFeature ( ) ;
510
+ context . Features . Set < IHttpResponseFeature > ( responseFeature ) ;
511
+ context . Request . ContentType = MultipartContentType ;
512
+ context . Request . Body = new NonSeekableReadStream ( formContent ) ;
513
+
514
+ IFormFeature formFeature = new FormFeature ( context . Request , new FormOptions ( ) ) ;
515
+ context . Features . Set < IFormFeature > ( formFeature ) ;
516
+
517
+ var exception = await Assert . ThrowsAsync < InvalidDataException > ( ( ) => context . Request . ReadFormAsync ( ) ) ;
518
+
519
+ Assert . Equal ( "Form section has invalid Content-Disposition value: " + InvalidContentDispositionValue , exception . Message ) ;
520
+ }
521
+
492
522
private Stream CreateFile ( int size )
493
523
{
494
524
var stream = new MemoryStream ( size ) ;
0 commit comments