2019-07-25 23:03:28 +03:00
|
|
|
<?php
|
|
|
|
|
2019-12-30 18:47:37 +03:00
|
|
|
namespace PhpZip\Tests;
|
|
|
|
|
|
|
|
use PhpZip\Exception\ZipException;
|
|
|
|
use PhpZip\ZipFile;
|
2019-07-25 23:03:28 +03:00
|
|
|
|
|
|
|
/**
|
2019-12-05 19:36:11 +03:00
|
|
|
* Class ZipSlipVulnerabilityTest.
|
2019-07-25 23:03:28 +03:00
|
|
|
*
|
|
|
|
* @see https://github.com/Ne-Lexa/php-zip/issues/39 Issue#31
|
|
|
|
* @see https://snyk.io/research/zip-slip-vulnerability Zip Slip Vulnerability
|
2019-12-05 19:36:11 +03:00
|
|
|
*
|
|
|
|
* @internal
|
|
|
|
*
|
|
|
|
* @small
|
2019-07-25 23:03:28 +03:00
|
|
|
*/
|
|
|
|
class ZipSlipVulnerabilityTest extends ZipTestCase
|
|
|
|
{
|
|
|
|
/**
|
2019-12-30 18:47:37 +03:00
|
|
|
* @throws ZipException
|
2019-07-25 23:03:28 +03:00
|
|
|
*/
|
|
|
|
public function testCreateSlipVulnerabilityFile()
|
|
|
|
{
|
|
|
|
$localFile = '../dir/./../../file.txt';
|
|
|
|
$zipFile = new ZipFile();
|
|
|
|
$zipFile->addFromString($localFile, 'contents');
|
2019-12-05 19:36:11 +03:00
|
|
|
static::assertContains($localFile, $zipFile->getListFiles());
|
2019-07-25 23:03:28 +03:00
|
|
|
$zipFile->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-30 18:47:37 +03:00
|
|
|
* @throws ZipException
|
2019-07-25 23:03:28 +03:00
|
|
|
*/
|
|
|
|
public function testUnpack()
|
|
|
|
{
|
2019-12-05 19:36:11 +03:00
|
|
|
static::assertTrue(mkdir($this->outputDirname, 0755, true));
|
2019-07-25 23:03:28 +03:00
|
|
|
|
|
|
|
$zipFile = new ZipFile();
|
|
|
|
$zipFile->addFromString('../dir/./../../file.txt', 'contents');
|
|
|
|
$zipFile->extractTo($this->outputDirname);
|
|
|
|
$zipFile->close();
|
|
|
|
|
|
|
|
$expectedExtractedFile = $this->outputDirname . '/dir/file.txt';
|
2019-12-05 19:36:11 +03:00
|
|
|
static::assertTrue(is_file($expectedExtractedFile));
|
2019-07-25 23:03:28 +03:00
|
|
|
}
|
|
|
|
}
|