2323namespace OCA \DAV \BulkUpload ;
2424
2525use OCP \AppFramework \Http ;
26+ use Psr \Log \LoggerInterface ;
2627use Sabre \DAV \Exception ;
2728use Sabre \DAV \Exception \BadRequest ;
2829use Sabre \DAV \Exception \LengthRequired ;
@@ -42,7 +43,10 @@ class MultipartRequestParser {
4243 /**
4344 * @throws BadRequest
4445 */
45- public function __construct (RequestInterface $ request ) {
46+ public function __construct (
47+ RequestInterface $ request ,
48+ protected LoggerInterface $ logger ,
49+ ) {
4650 $ stream = $ request ->getBody ();
4751 $ contentType = $ request ->getHeader ('Content-Type ' );
4852
@@ -78,7 +82,7 @@ private function parseBoundaryFromHeaders(string $contentType): string {
7882 $ boundaryValue = trim ($ boundaryValue );
7983
8084 // Remove potential quotes around boundary value.
81- if (substr ($ boundaryValue , 0 , 1 ) == '" ' && substr ($ boundaryValue , -1 ) == '" ' ) {
85+ if (substr ($ boundaryValue , 0 , 1 ) === '" ' && substr ($ boundaryValue , -1 ) = == '" ' ) {
8286 $ boundaryValue = substr ($ boundaryValue , 1 , -1 );
8387 }
8488
@@ -179,6 +183,11 @@ private function readPartHeaders(): array {
179183 throw new Exception ('An error occurred while reading headers of a part ' );
180184 }
181185
186+ if (!str_contains ($ line , ': ' )) {
187+ $ this ->logger ->error ('Header missing ":" on bulk request: ' . json_encode ($ line ));
188+ throw new Exception ('An error occurred while reading headers of a part ' , Http::STATUS_BAD_REQUEST );
189+ }
190+
182191 try {
183192 [$ key , $ value ] = explode (': ' , $ line , 2 );
184193 $ headers [strtolower (trim ($ key ))] = trim ($ value );
0 commit comments