Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/dav/lib/Connector/Sabre/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ protected function sanitizeMtime($mtimeFromRequest) {
throw new \InvalidArgumentException('X-OC-MTime header must be an integer (unix timestamp).');
}

// Prevent writing invalid mtime (timezone-proof)
if ((int)$mtimeFromRequest <= 24 * 60 * 60) {
throw new \InvalidArgumentException('X-OC-MTime header must be a valid positive integer');
}

return (int)$mtimeFromRequest;
}
}
24 changes: 11 additions & 13 deletions apps/dav/tests/unit/Connector/Sabre/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,28 +361,28 @@ public function legalMtimeProvider() {
'expected result' => null
],
"castable string (int)" => [
'HTTP_X_OC_MTIME' => "34",
'expected result' => 34
'HTTP_X_OC_MTIME' => "987654321",
'expected result' => 987654321
],
"castable string (float)" => [
'HTTP_X_OC_MTIME' => "34.56",
'expected result' => 34
'HTTP_X_OC_MTIME' => "123456789.56",
'expected result' => 123456789
],
"float" => [
'HTTP_X_OC_MTIME' => 34.56,
'expected result' => 34
'HTTP_X_OC_MTIME' => 123456789.56,
'expected result' => 123456789
],
"zero" => [
'HTTP_X_OC_MTIME' => 0,
'expected result' => 0
'expected result' => null
],
"zero string" => [
'HTTP_X_OC_MTIME' => "0",
'expected result' => 0
'expected result' => null
],
"negative zero string" => [
'HTTP_X_OC_MTIME' => "-0",
'expected result' => 0
'expected result' => null
],
"string starting with number following by char" => [
'HTTP_X_OC_MTIME' => "2345asdf",
Expand All @@ -398,11 +398,11 @@ public function legalMtimeProvider() {
],
"negative int" => [
'HTTP_X_OC_MTIME' => -34,
'expected result' => -34
'expected result' => null
],
"negative float" => [
'HTTP_X_OC_MTIME' => -34.43,
'expected result' => -34
'expected result' => null
],
];
}
Expand All @@ -421,7 +421,6 @@ public function testPutSingleFileLegalMtime($requestMtime, $resultMtime) {

if ($resultMtime === null) {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage("X-OC-MTime header must be an integer (unix timestamp).");
}

$this->doPut($file, null, $request);
Expand All @@ -447,7 +446,6 @@ public function testChunkedPutLegalMtime($requestMtime, $resultMtime) {

if ($resultMtime === null) {
$this->expectException(\Sabre\DAV\Exception::class);
$this->expectExceptionMessage("X-OC-MTime header must be an integer (unix timestamp).");
}

$this->doPut($file.'-chunking-12345-2-0', null, $request);
Expand Down
48 changes: 47 additions & 1 deletion apps/dav/tests/unit/Connector/Sabre/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,54 @@ public function testSharePermissions($type, $user, $permissions, $expected) {
->disableOriginalConstructor()
->getMock();

$node = new \OCA\DAV\Connector\Sabre\File($view, $info);
$node = new \OCA\DAV\Connector\Sabre\File($view, $info);
$this->invokePrivate($node, 'shareManager', [$shareManager]);
$this->assertEquals($expected, $node->getSharePermissions($user));
}

public function sanitizeMtimeProvider() {
return [
[123456789, 123456789],
['987654321', 987654321],
];
}

/**
* @dataProvider sanitizeMtimeProvider
*/
public function testSanitizeMtime($mtime, $expected) {
$view = $this->getMockBuilder(View::class)
->disableOriginalConstructor()
->getMock();
$info = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()
->getMock();

$node = new \OCA\DAV\Connector\Sabre\File($view, $info);
$result = $this->invokePrivate($node, 'sanitizeMtime', [$mtime]);
$this->assertEquals($expected, $result);
}

public function invalidSanitizeMtimeProvider() {
return [
[-1337], [0], ['abcdef'], ['-1337'], ['0'], [12321], [24 * 60 * 60 - 1]
];
}

/**
* @dataProvider invalidSanitizeMtimeProvider
*/
public function testInvalidSanitizeMtime($mtime) {
$this->expectException(\InvalidArgumentException::class);

$view = $this->getMockBuilder(View::class)
->disableOriginalConstructor()
->getMock();
$info = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()
->getMock();

$node = new \OCA\DAV\Connector\Sabre\File($view, $info);
$result = $this->invokePrivate($node, 'sanitizeMtime', [$mtime]);
}
}