Skip to content

Commit c695d5c

Browse files
committed
Minor Correction
Sanitize font name.
1 parent a9ac138 commit c695d5c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/PhpSpreadsheet/Writer/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ private function createCSSStyleFont(Font $font): array
10391039
}
10401040

10411041
$css['color'] = '#' . $font->getColor()->getRGB();
1042-
$css['font-family'] = '\'' . $font->getName() . '\'';
1042+
$css['font-family'] = '\'' . htmlspecialchars((string) $font->getName(), ENT_QUOTES) . '\'';
10431043
$css['font-size'] = $font->getSize() . 'pt';
10441044

10451045
return $css;

tests/PhpSpreadsheetTests/Writer/Html/XssVulnerabilityTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,21 @@ public function testXssInComment(string $xssTextString, ?string $expected = null
5959
self::assertStringContainsString($expected, $verify);
6060
$spreadsheet->disconnectWorksheets();
6161
}
62+
63+
public function testXssInFontName(): void
64+
{
65+
$spreadsheet = new Spreadsheet();
66+
$sheet = $spreadsheet->getActiveSheet();
67+
$sheet->getCell('A1')->setValue('here');
68+
$used = 'Calibri</style><script type="text/javascript">alert("hello");</script><style type="text/css">';
69+
$expected = "font-family:'Calibri&lt;/style&gt;&lt;script type=&quot;text/javascript&quot;&gt;alert(&quot;hello&quot;);&lt;/script&gt;&lt;style type=&quot;text/css&quot;&gt;'";
70+
$sheet->getStyle('A1')->getFont()->setName($used);
71+
72+
$writer = new Html($spreadsheet);
73+
$verify = $writer->generateHtmlAll();
74+
// Ensure that executable js has been stripped
75+
self::assertStringNotContainsString($expected, $used);
76+
self::assertStringContainsString($expected, $verify);
77+
$spreadsheet->disconnectWorksheets();
78+
}
6279
}

0 commit comments

Comments
 (0)