I would like to suggest a rewrite of the Archiver classes. At the moment the Archiver namespace consist of 2 Archiver classes: Zip and Tar. Especially the ArchiveTar class is a mess and breaks pretty much every coding standard. How about a rewrite of the Zip and Tar classes to utilize the PharData class as backend? I believe PharData is included in PHP since 5.3 so that shouldn't provide any problems.

I could pick this one up and provide a patch for the rewrite if you all agree.

Please let me know what you think.

Comments

Gun5m0k3 created an issue. See original summary.

mvdgun’s picture

Title: Rewrite the Archiver classes to user PharData » Rewrite the Archiver classes to use PharData
dawehner’s picture

This sounds like an excellent idea, given it avoids us to maintain these files basically.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

sjerdo’s picture

Initial attempt of implementation of PharData for handling tar files. All ArchiveTar references are removed from the code.

sjerdo’s picture

StatusFileSize
new96.11 KB
new2.57 KB

Unfortunately tests fail. Some tests fail due to an incorrect file extension. The configuration import form does not validate for correct extensions (tar.gz tgz tar.bz2). I have added validation for this like in update.manager.inc.

Extracting the Tar archive with PharData::extractTo fails with an exception, possibly since it is unable to restore the file permissions:

Extraction from phar "/tmp/update-cache-58e7ca78/test_module.tar.gz" failed: Cannot extract "test_module/test_module.yml" to "temporary://update-extraction-58e7ca78/test_module/test_module.yml", setting file permissions failed

Somehow the permissions cannot be set (See phar_object.c source).

Code is changed for using correct file extensions and avoiding the extractTo method.

dawehner’s picture

One note: While not longer using the archiver internally is totally an option, I think we cannot remove the library itself, given others might rely on it.

Do you mind figuring out whether phar is enabled by the usual PHP distributors (xampp, osx/ubuntu hosters etc.)?

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

sjerdo’s picture

Status: Active » Needs work

@dawehner I agree with not removing the library itself, but we could deprecate the use of it and remove it in Drupal 9.

PHP documentation states that Phar is included in PHP since PHP 5.3.0 and enabled by default: http://php.net/manual/en/phar.installation.php
However, the zlib and/or bzip2 extension(s) should be enabled to support compressed archives: http://php.net/manual/en/phar.requirements.php

sjerdo’s picture

StatusFileSize
new12.93 KB

Updated patch and rebased for 8.7.x branch.
No longer removes the ArchiveTar library.

geerlingguy’s picture

So... after an 8.6.x security update that adds Drupal\Core\Security\PharExtensionInterceptor, it seems that we might not be able to use PharData with gzip/zip/tarballs, at least according to my own custom code which is doing that and now is broken.

Code:

$phar = new PharData($archive_path);

Results in:

Unexpected file extension in "phar:///var/www/html/docroot/sites/default/files/project-starter-templates/php-template.tar.gz/"

geerlingguy’s picture

StatusFileSize
new1.17 KB

Uploading a patch which at least allows one extension (.gz) to work with PharData, though this is not vetted for security, and I'm only uploading it here because if someone else wants to figure out how to still be able to handle anything besides .phar files with PharData post-8.6.x, this seems to be the only way to do it :(

Maybe we could find an amicable way to add a list of 'PharData-allowed extensions' and default it to .phar, .tar, .gz, .zip?

alexpott’s picture

yeah #14 is not a great idea from a security stand point because it would people upload malicious phar files with a gz extension and if a file_exists() call is made on that do an RCE.

effulgentsia’s picture

@alexpott: what would you think of an approach where instead of whitelisting .gz, we check the backtrace and whitelist paths that come from PharData's constructor? Is it reasonable to assume that callers of new PharData need to be responsible for only passing trusted paths?

geerlingguy’s picture

Is it reasonable to assume that callers of new PharData need to be responsible for only passing trusted paths?

I think this would be a reasonable conclusion. I have a couple D7 sites which are using PharData as well, and I know I'm going to run into some pain when I try porting that code to D8/D9 because of this new PharData interceptor :(

I would imagine for the smaller percentage of sites that do need to use it, they should know the risks and assume responsibility for the code.

As it is, the security fix has effectively disabled one of the PHP languages core libraries for all Drupal sites.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.