ZipSlipVulnerabilityTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. * @covers
  13. */
  14. class ZipSlipVulnerabilityTest extends ZipTestCase
  15. {
  16. /**
  17. * @throws Exception\ZipException
  18. */
  19. public function testCreateSlipVulnerabilityFile()
  20. {
  21. $localFile = '../dir/./../../file.txt';
  22. $zipFile = new ZipFile();
  23. $zipFile->addFromString($localFile, 'contents');
  24. static::assertContains($localFile, $zipFile->getListFiles());
  25. $zipFile->close();
  26. }
  27. /**
  28. * @throws Exception\ZipException
  29. */
  30. public function testUnpack()
  31. {
  32. static::assertTrue(mkdir($this->outputDirname, 0755, true));
  33. $zipFile = new ZipFile();
  34. $zipFile->addFromString('../dir/./../../file.txt', 'contents');
  35. $zipFile->extractTo($this->outputDirname);
  36. $zipFile->close();
  37. $expectedExtractedFile = $this->outputDirname . '/dir/file.txt';
  38. static::assertTrue(is_file($expectedExtractedFile));
  39. }
  40. }