aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/BulkUpload/MultipartRequestParser.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/BulkUpload/MultipartRequestParser.php')
-rw-r--r--apps/dav/lib/BulkUpload/MultipartRequestParser.php39
1 files changed, 25 insertions, 14 deletions
diff --git a/apps/dav/lib/BulkUpload/MultipartRequestParser.php b/apps/dav/lib/BulkUpload/MultipartRequestParser.php
index 107c67ea691..96a90f82cde 100644
--- a/apps/dav/lib/BulkUpload/MultipartRequestParser.php
+++ b/apps/dav/lib/BulkUpload/MultipartRequestParser.php
@@ -134,7 +134,10 @@ class MultipartRequestParser {
$headers = $this->readPartHeaders();
- $content = $this->readPartContent((int)$headers['content-length'], $headers['x-file-md5']);
+ $length = (int)$headers['content-length'];
+
+ $this->validateHash($length, $headers['x-file-md5'] ?? '', $headers['oc-checksum'] ?? '');
+ $content = $this->readPartContent($length);
return [$headers, $content];
}
@@ -184,8 +187,9 @@ class MultipartRequestParser {
throw new LengthRequired('The Content-Length header must not be null.');
}
- if (!isset($headers['x-file-md5'])) {
- throw new BadRequest('The X-File-MD5 header must not be null.');
+ // TODO: Drop $md5 condition when the latest desktop client that uses it is no longer supported.
+ if (!isset($headers['x-file-md5']) && !isset($headers['oc-checksum'])) {
+ throw new BadRequest('The hash headers must not be null.');
}
return $headers;
@@ -197,13 +201,7 @@ class MultipartRequestParser {
* @throws Exception
* @throws BadRequest
*/
- private function readPartContent(int $length, string $md5): string {
- $computedMd5 = $this->computeMd5Hash($length);
-
- if ($md5 !== $computedMd5) {
- throw new BadRequest('Computed md5 hash is incorrect.');
- }
-
+ private function readPartContent(int $length): string {
if ($length === 0) {
$content = '';
} else {
@@ -225,12 +223,25 @@ class MultipartRequestParser {
}
/**
- * Compute the MD5 hash of the next x bytes.
+ * Compute the MD5 or checksum hash of the next x bytes.
+ * TODO: Drop $md5 argument when the latest desktop client that uses it is no longer supported.
*/
- private function computeMd5Hash(int $length): string {
- $context = hash_init('md5');
+ private function validateHash(int $length, string $fileMd5Header, string $checksumHeader): void {
+ if ($checksumHeader !== '') {
+ [$algorithm, $hash] = explode(':', $checksumHeader, 2);
+ } elseif ($fileMd5Header !== '') {
+ $algorithm = 'md5';
+ $hash = $fileMd5Header;
+ } else {
+ throw new BadRequest('No hash provided.');
+ }
+
+ $context = hash_init($algorithm);
hash_update_stream($context, $this->stream, $length);
fseek($this->stream, -$length, SEEK_CUR);
- return hash_final($context);
+ $computedHash = hash_final($context);
+ if ($hash !== $computedHash) {
+ throw new BadRequest("Computed $algorithm hash is incorrect ($computedHash).");
+ }
}
}