ZipSlipVulnerabilityTest.php 1.1 KB

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