-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restrict Internet Protocols for Linked Images
Do not allow use of Php propietary protocols to retrieve linked images. Restrict to http, https, ftp, file, and s3.
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html; | ||
|
||
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException; | ||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class HtmlImage2Test extends TestCase | ||
{ | ||
public function testCanInsertImageGoodProtocol(): void | ||
{ | ||
if (getenv('SKIP_URL_IMAGE_TEST') === '1') { | ||
self::markTestSkipped('Skipped due to setting of environment variable'); | ||
} | ||
$imagePath = 'https://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png'; | ||
$html = '<table> | ||
<tr> | ||
<td><img src="' . $imagePath . '" alt="test image voilà"></td> | ||
</tr> | ||
</table>'; | ||
$filename = HtmlHelper::createHtml($html); | ||
$spreadsheet = HtmlHelper::loadHtmlIntoSpreadsheet($filename, true); | ||
$firstSheet = $spreadsheet->getSheet(0); | ||
|
||
/** @var Drawing $drawing */ | ||
$drawing = $firstSheet->getDrawingCollection()[0]; | ||
self::assertEquals($imagePath, $drawing->getPath()); | ||
self::assertEquals('A1', $drawing->getCoordinates()); | ||
} | ||
|
||
public function testCannotInsertImageBadProtocol(): void | ||
{ | ||
$this->expectException(SpreadsheetException::class); | ||
$this->expectExceptionMessage('Invalid protocol for linked drawing'); | ||
$imagePath = 'httpx://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png'; | ||
$html = '<table> | ||
<tr> | ||
<td><img src="' . $imagePath . '" alt="test image voilà"></td> | ||
</tr> | ||
</table>'; | ||
$filename = HtmlHelper::createHtml($html); | ||
$spreadsheet = HtmlHelper::loadHtmlIntoSpreadsheet($filename, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.