Skip to content

Commit 762d969

Browse files
Merge pull request #55283 from nextcloud/jtr/fix/issue-55276
fix(workflowenigne): stricter length header handling
2 parents 2c0f22e + f503975 commit 762d969

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

apps/workflowengine/lib/Check/FileSize.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,36 @@ public function validateCheck($operator, $value): void {
5757
}
5858
}
5959

60+
/**
61+
* Gets the file size from HTTP headers.
62+
*
63+
* Checks 'OC-Total-Length' first; if unavailable and the method is POST or PUT,
64+
* checks 'Content-Length'. Returns the size as int, float, or false if not found or invalid.
65+
*
66+
* @return int|float|false File size in bytes, or false if unavailable.
67+
*/
6068
protected function getFileSizeFromHeader(): int|float|false {
69+
// Already have it cached?
6170
if ($this->size !== null) {
6271
return $this->size;
6372
}
6473

6574
$size = $this->request->getHeader('OC-Total-Length');
6675
if ($size === '') {
67-
if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
76+
// Try fallback for upload methods
77+
$method = $this->request->getMethod();
78+
if (in_array($method, ['POST', 'PUT'], true)) {
6879
$size = $this->request->getHeader('Content-Length');
6980
}
7081
}
7182

72-
if ($size === '' || !is_numeric($size)) {
73-
$size = false;
83+
if ($size !== '' && is_numeric($size)) {
84+
$this->size = Util::numericToNumber($size);
85+
} else {
86+
// No valid size header found
87+
$this->size = false;
7488
}
7589

76-
$this->size = Util::numericToNumber($size);
7790
return $this->size;
7891
}
7992

0 commit comments

Comments
 (0)