From 1534b24e3802836f06637e11ee67fc9f5515a82d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 26 Jul 2021 17:44:52 +0200 Subject: [PATCH 1/2] dont apply jail search filter is on the root the extra '/' breaks things and the filter wouldn't do anything anyway except making the databases job harder Signed-off-by: Robin Appelman --- lib/private/Files/Cache/Wrapper/CacheJail.php | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/private/Files/Cache/Wrapper/CacheJail.php b/lib/private/Files/Cache/Wrapper/CacheJail.php index 38f47668d5d59..2dff76333ad72 100644 --- a/lib/private/Files/Cache/Wrapper/CacheJail.php +++ b/lib/private/Files/Cache/Wrapper/CacheJail.php @@ -306,17 +306,21 @@ public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, } public function getQueryFilterForStorage(): ISearchOperator { - return new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, - [ - $this->getCache()->getQueryFilterForStorage(), - new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, - [ - new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'path', $this->getGetUnjailedRoot()), - new SearchComparison(ISearchComparison::COMPARE_LIKE, 'path', $this->getGetUnjailedRoot() . '/%'), - ], - ) - ] - ); + if ($this->root !== '' && $this->root !== '/') { + return new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, + [ + $this->getCache()->getQueryFilterForStorage(), + new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, + [ + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'path', $this->getGetUnjailedRoot()), + new SearchComparison(ISearchComparison::COMPARE_LIKE, 'path', $this->getGetUnjailedRoot() . '/%'), + ], + ) + ] + ); + } else { + return $this->getCache()->getQueryFilterForStorage(); + } } public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEntry { From 69e650d4b0013cd94d8a54c78dcefe9db56bfb90 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 28 Jul 2021 17:11:12 +0200 Subject: [PATCH 2/2] add test for searching within a "root jail" Signed-off-by: Robin Appelman --- .../lib/Files/Cache/Wrapper/CacheJailTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php index d9f7af1f03435..4c3dce740878b 100644 --- a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php +++ b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php @@ -200,4 +200,22 @@ public function testSearchNested() { $this->assertCount(1, $result); $this->assertEquals('asd', $result[0]['path']); } + + public function testRootJail() { + $this->storage->getScanner()->scan(''); + $file1 = 'foo'; + $file2 = 'foo/bar'; + $file3 = 'foo/bar/asd'; + $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder']; + + $this->sourceCache->put($file1, $data1); + $this->sourceCache->put($file2, $data1); + $this->sourceCache->put($file3, $data1); + + $nested = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, ''); + + $result = $nested->search('%asd%'); + $this->assertCount(1, $result); + $this->assertEquals('foo/bar/asd', $result[0]['path']); + } }