2
0

ZipSlipVulnerabilityTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace PhpZip;
  3. /**
  4. * Class ZipSlipVulnerabilityTest
  5. *
  6. * @package PhpZip
  7. * @see https://github.com/Ne-Lexa/php-zip/issues/39 Issue#31
  8. * @see https://snyk.io/research/zip-slip-vulnerability Zip Slip Vulnerability
  9. */
  10. class ZipSlipVulnerabilityTest extends ZipTestCase
  11. {
  12. /**
  13. * @throws Exception\ZipException
  14. */
  15. public function testCreateSlipVulnerabilityFile()
  16. {
  17. $localFile = '../dir/./../../file.txt';
  18. $zipFile = new ZipFile();
  19. $zipFile->addFromString($localFile, 'contents');
  20. self::assertContains($localFile, $zipFile->getListFiles());
  21. $zipFile->close();
  22. }
  23. /**
  24. * @throws Exception\ZipException
  25. */
  26. public function testUnpack()
  27. {
  28. $this->assertTrue(mkdir($this->outputDirname, 0755, true));
  29. $zipFile = new ZipFile();
  30. $zipFile->addFromString('../dir/./../../file.txt', 'contents');
  31. $zipFile->extractTo($this->outputDirname);
  32. $zipFile->close();
  33. $expectedExtractedFile = $this->outputDirname . '/dir/file.txt';
  34. self::assertTrue(is_file($expectedExtractedFile));
  35. }
  36. }