From 8af50563c678829769d67757614d61ac6e1d3dd2 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Fri, 20 Oct 2017 00:19:35 +0300 Subject: [PATCH 1/2] Revert "Exclude mimetypelist.js from integrity check" This reverts commit 406d173bc08d2f8d0878340f6e54ac111d6d73c1. --- lib/private/IntegrityCheck/Checker.php | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/lib/private/IntegrityCheck/Checker.php b/lib/private/IntegrityCheck/Checker.php index fdecc7761c43..0852a5734b6d 100644 --- a/lib/private/IntegrityCheck/Checker.php +++ b/lib/private/IntegrityCheck/Checker.php @@ -179,22 +179,6 @@ private function generateHashes(\RecursiveIteratorIterator $iterator, continue; } - $exclusionList = [ - '/core/js/mimetypelist.js' - ]; - - $found = false; - foreach ($exclusionList as $entry) { - if($filename === $this->environmentHelper->getServerRoot() . $entry) { - $found = true; - break; - } - } - - if ($found) { - continue; - } - // The .user.ini and the .htaccess file of ownCloud can contain some // custom modifications such as for example the maximum upload size // to ensure that this will not lead to false positives this will From 8c8c3542ecbdf0420b71cc2458d3c0bd8d70456b Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Fri, 20 Oct 2017 01:56:43 +0300 Subject: [PATCH 2/2] Add ability to exclude items from signing by path and filename --- .../ExcludeFileByNameFilterIterator.php | 23 ++++++++++++++-- .../app/core/js/mimetypelist.js | 1 + .../ExcludeFileByNameFilterIteratorTest.php | 27 +++++++++++++------ 3 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 tests/data/integritycheck/app/core/js/mimetypelist.js diff --git a/lib/private/IntegrityCheck/Iterator/ExcludeFileByNameFilterIterator.php b/lib/private/IntegrityCheck/Iterator/ExcludeFileByNameFilterIterator.php index 8b197bd98781..b5f933a16862 100644 --- a/lib/private/IntegrityCheck/Iterator/ExcludeFileByNameFilterIterator.php +++ b/lib/private/IntegrityCheck/Iterator/ExcludeFileByNameFilterIterator.php @@ -23,8 +23,8 @@ namespace OC\IntegrityCheck\Iterator; /** - * Class ExcludeFileByNameFilterIterator provides a custom iterator which excludes - * entries with the specified file name from the file list. These file names are matched exactly. + * Class ExcludeFileByNameFilterIterator provides a custom iterator which excludes + * entries with the specified file name or name part from the file list. * * @package OC\Integritycheck\Iterator */ @@ -53,6 +53,18 @@ class ExcludeFileByNameFilterIterator extends \RecursiveFilterIterator { private $excludedFileNamePatterns = [ '/^\.webapp-owncloud-.*/', // Gentoo/Funtoo & derivatives use a tool known as webapp-config to manage wep-apps. ]; + + /** + * Array of excluded path and file name parts. Those are not scanned by the integrity checker. + * These strings are regular expressions and any filepath + * matching these expressions are ignored. + * + * @var array + */ + private $excludedFilePathPatterns = [ + '|/core/js/mimetypelist.js$|', // this file can be regenerated with additional entries with occ maintenance:mimetype:update-js + ]; + /** * @return bool @@ -75,6 +87,13 @@ public function accept() { return false; } } + + $currentFilePath = $current->getPathname(); + foreach ($this->excludedFilePathPatterns as $pattern){ + if (preg_match($pattern, $currentFilePath) > 0){ + return false; + } + } return true; } diff --git a/tests/data/integritycheck/app/core/js/mimetypelist.js b/tests/data/integritycheck/app/core/js/mimetypelist.js new file mode 100644 index 000000000000..9e26dfeeb6e6 --- /dev/null +++ b/tests/data/integritycheck/app/core/js/mimetypelist.js @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php b/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php index f9810bb3692d..9aa8c09b1530 100644 --- a/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php +++ b/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php @@ -40,24 +40,31 @@ public function setUp() { public function fileNameProvider(){ return [ - ['a file', true], - ['Thumbs.db', false], - ['another file', true], - ['.directory', false], - ['.webapp-owncloud-obee', false], - ['wx.webapp-owncloud-obee', true], + ['', 'a file', true], + ['', 'Thumbs.db', false], + ['', 'another file', true], + ['', '.directory', false], + ['', '.webapp-owncloud-obee', false], + ['', 'wx.webapp-owncloud-obee', true], + ['/core/js', 'mimetypelist.js', false], + ['/core/css', 'mimetypelist.js', true], + ['/core/js', 'typelist.js', true], + ['/hardcore/js', 'mimetypelist.js', true], + ['/js', 'mimetypelist.js', true], + ]; } /** * @dataProvider fileNameProvider + * @param string $path * @param string $fileName * @param bool $expectedResult */ - public function testAcceptForFiles($fileName, $expectedResult){ + public function testAcceptForFiles($path, $fileName, $expectedResult){ $iteratorMock = $this->getMockBuilder(\RecursiveDirectoryIterator::class) ->disableOriginalConstructor() - ->setMethods(['getFilename', 'isDir']) + ->setMethods(['getPathname', 'getFilename', 'isDir']) ->getMock() ; $iteratorMock->method('getFilename') @@ -66,6 +73,9 @@ public function testAcceptForFiles($fileName, $expectedResult){ $iteratorMock->method('isDir') ->will($this->returnValue(false)); + $iteratorMock->method('getPathname') + ->will($this->returnValue("$path/$fileName")); + $this->filter->method('current') ->will($this->returnValue($iteratorMock)) ; @@ -73,6 +83,7 @@ public function testAcceptForFiles($fileName, $expectedResult){ $actualResult = $this->filter->accept(); $this->assertEquals($expectedResult, $actualResult); } + /** * @dataProvider fileNameProvider