1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-01-17 15:28:14 +01:00
php-zip/tests/ZipSlipVulnerabilityTest.php

48 lines
1.2 KiB
PHP
Raw Normal View History

2019-07-25 23:03:28 +03:00
<?php
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
{
/**
* @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();
}
/**
* @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
}
}