mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-16 13:06:31 +00:00
Minor Correction
Sanitize font name.
This commit is contained in:
@@ -1039,7 +1039,7 @@ class Html extends BaseWriter
|
||||
}
|
||||
|
||||
$css['color'] = '#' . $font->getColor()->getRGB();
|
||||
$css['font-family'] = '\'' . $font->getName() . '\'';
|
||||
$css['font-family'] = '\'' . htmlspecialchars((string) $font->getName(), ENT_QUOTES) . '\'';
|
||||
$css['font-size'] = $font->getSize() . 'pt';
|
||||
|
||||
return $css;
|
||||
|
||||
@@ -59,4 +59,21 @@ class XssVulnerabilityTest extends Functional\AbstractFunctional
|
||||
self::assertStringContainsString($expected, $verify);
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
}
|
||||
|
||||
public function testXssInFontName(): void
|
||||
{
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->getCell('A1')->setValue('here');
|
||||
$used = 'Calibri</style><script type="text/javascript">alert("hello");</script><style type="text/css">';
|
||||
$expected = "font-family:'Calibri</style><script type="text/javascript">alert("hello");</script><style type="text/css">'";
|
||||
$sheet->getStyle('A1')->getFont()->setName($used);
|
||||
|
||||
$writer = new Html($spreadsheet);
|
||||
$verify = $writer->generateHtmlAll();
|
||||
// Ensure that executable js has been stripped
|
||||
self::assertStringNotContainsString($expected, $used);
|
||||
self::assertStringContainsString($expected, $verify);
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user