Headline
CVE-2020-7063: PHP :: Sec Bug #79082 :: Files added to tar with Phar::buildFromIterator have all-access permissions
In PHP versions 7.2.x below 7.2.28, 7.3.x below 7.3.15 and 7.4.x below 7.4.3, when creating PHAR archive using PharData::buildFromIterator() function, the files are added with default permissions (0666, or all access) even if the original files on the filesystem were with more restrictive permissions. This may result in files having more lax permissions than intended when such archive is extracted.
Sec Bug #79082
Files added to tar with Phar::buildFromIterator have all-access permissions
Submitted:
2020-01-08 17:42 UTC
Modified:
2020-02-17 08:21 UTC
From:
dr at loopia dot rs
Assigned:
stas (profile)
Status:
Closed
Package:
PHAR related
PHP Version:
7.2.27
OS:
Ubuntu 16.04.6 LTS
Private report:
No
CVE-ID:
2020-7063
[2020-01-08 17:42 UTC] dr at loopia dot rs
Description:
When using PharData::buildFromIterator() to create a Tar archive file permissions are not kept.
Same bug as #77022 but its triggered by using buildFromIterator. Making a new report rather than comment on #77022 because #77022 was marked as "SEC BUG".
Even adding the same file with iterator and with addFile($file, ‘new-name’) will result in a tar archive with two files with different permissions.
Test script:
https://3v4l.org/qCPRH
<?php var_dump(decoct(umask(22))); $srcDir = '/tmp/files’; mkdir($srcDir); foreach([1, 2] as $i){ $file = tempnam($srcDir, ‘test’); printf("File$i - %o\n", stat($file)[‘mode’]); } $phar = new \PharData('/tmp/test.tar’, null, null, \Phar::TAR); $phar->buildFromIterator(new \RecursiveDirectoryIterator($srcDir, \FilesystemIterator::SKIP_DOTS), $srcDir);
$phar->addFile($file, ‘added-with-add-file’); $phar->extractTo(‘/tmp/pharFiles’);
foreach(new \RecursiveDirectoryIterator('/tmp/pharFiles’, \FilesystemIterator::SKIP_DOTS) as $iFile) { printf('From ' . ($iFile->getFilename() === ‘added-with-add-file’ ? ‘addFile’:’Iterator’). " - %o\n", $iFile->getPerms()); }
Expected result:
Files added to tar using PharData::buildFromIterator should keep the original permissions or respect the umask, same as files added by using PharData::addFile.
From addFile - 100600 From Iterator - 100600
Actual result:
Files added from iterator don’t keep correct permissions
From addFile - 100600 From Iterator - 100666
Before #77022 was fixed From addFile - 100666 From Iterator - 100666
Patches
Add a Patch
Pull Requests
Add a Pull Request
History
AllCommentsChangesGit/SVN commitsRelated reports
[2020-02-16 06:00 UTC] [email protected]
-PHP Version: 7.3.13 +PHP Version: 7.2.28 -CVE-ID: +CVE-ID: 2020-7063
[2020-02-16 06:00 UTC] [email protected]
-PHP Version: 7.2.28 +PHP Version: 7.2.27
[2020-02-16 06:02 UTC] [email protected]
-Summary: Files added to tar with Phar::buildFromIterator trigger bug #77022 +Summary: Files added to tar with Phar::buildFromIterator have all-access permissions
[2020-02-16 06:18 UTC] [email protected]
-Assigned To: +Assigned To: stas
[2020-02-17 08:21 UTC] [email protected]
-Status: Assigned +Status: Closed