Skip to content

Commit 92afd81

Browse files
committed
fix XSS vulnerabilities in examples
1 parent 0a75590 commit 92afd81

5 files changed

Lines changed: 19 additions & 44 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [5.2.8](https://github.com/spipu/html2pdf/compare/v5.2.7...v5.2.8) - 2023-07-18
6+
7+
* fix XSS vulnerabilities in examples `example9.php` and `forms.php` - thanks to Michał Majchrowicz, Livio Victoriano and Zbigniew Piotrak from [AFINE Team](https://www.afine.pl/)
8+
59
## [5.2.7](https://github.com/spipu/html2pdf/compare/v5.2.6...v5.2.7) - 2023-02-02
610

7-
* fix phunit compatibility
11+
* fix phunit compatibility
812

913
## [5.2.6](https://github.com/spipu/html2pdf/compare/v5.2.5...v5.2.6) - 2023-01-28
1014

examples/example09.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,18 @@
1515
use Spipu\Html2Pdf\Exception\Html2PdfException;
1616
use Spipu\Html2Pdf\Exception\ExceptionFormatter;
1717

18-
if (isset($_SERVER['REQUEST_URI'])) {
19-
$generate = isset($_GET['make_pdf']);
20-
$nom = isset($_GET['nom']) ? $_GET['nom'] : 'inconnu';
21-
$url = dirname($_SERVER['REQUEST_URI']);
22-
if (substr($url, 0, 7)!=='http://') {
23-
$url = 'http://'.$_SERVER['HTTP_HOST'].$url;
24-
}
25-
} else {
18+
$name = 'spipu';
19+
$generate = false;
20+
21+
if (isset($_GET['nom'])) {
22+
$generate = true;
23+
$name = $_GET['nom'];
24+
$name = preg_replace('/[^a-zA-Z0-9]/isU', '', $name);
25+
$name = substr($name, 0, 26);
26+
} else if (!isset($_SERVER['REQUEST_URI'])) {
2627
$generate = true;
27-
$nom = 'spipu';
28-
$url = 'http://localhost/html2pdf/examples/';
2928
}
3029

31-
$nom = substr(preg_replace('/[^a-zA-Z0-9]/isU', '', $nom), 0, 26);
32-
$url.= '/res/example09.png.php?px=5&py=20';
33-
34-
3530
if ($generate) {
3631
ob_start();
3732
} else {
@@ -49,13 +44,13 @@
4944
<br>
5045
Ceci est un exemple de génération de PDF via un bouton :)<br>
5146
<br>
52-
<img src="<?php echo $url; ?>" alt="image_php" ><br>
47+
<img src="http://html2pdf-dev.lxd/res/example09.png.php?px=5&amp;py=20" alt="image_php" ><br>
5348
<br>
5449
<?php
5550
if ($generate) {
5651
?>
57-
Bonjour <b><?php echo $nom; ?></b>, ton nom peut s'écrire : <br>
58-
<barcode type="C39" value="<?php echo strtoupper($nom); ?>" style="color: #770000" ></barcode><hr>
52+
Bonjour <b><?php echo $name; ?></b>, ton nom peut s'écrire : <br>
53+
<barcode type="C39" value="<?php echo strtoupper($name); ?>" style="color: #770000" ></barcode><hr>
5954
<br>
6055
<?php
6156
}

examples/forms.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@
1515
use Spipu\Html2Pdf\Exception\Html2PdfException;
1616
use Spipu\Html2Pdf\Exception\ExceptionFormatter;
1717

18-
// for display the post information
19-
if (isset($_POST['test'])) {
20-
echo '<pre>';
21-
echo htmlentities(print_r($_POST, true));
22-
echo '</pre>';
23-
exit;
24-
}
25-
2618
try {
2719
ob_start();
2820
require dirname(__FILE__).'/res/forms.php';

examples/res/forms.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
<?php
2-
3-
if (isset($_SERVER['REQUEST_URI'])) {
4-
$url = $_SERVER['REQUEST_URI'];
5-
if (substr($url, 0, 7)!=='http://') {
6-
$url = 'http://'.$_SERVER['HTTP_HOST'];
7-
if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT']!=80) {
8-
$url.= ':'.$_SERVER['SERVER_PORT'];
9-
}
10-
$url.= $_SERVER['REQUEST_URI'];
11-
}
12-
} else {
13-
$url = 'http://localhost/html2pdf/examples/forms.php';
14-
}
15-
?>
161
<style type="text/css">
172
li
183
{ font-size: 10pt; }
@@ -29,7 +14,7 @@
2914
<page footer="form,date,time">
3015
<h1>Test de formulaire</h1><br>
3116
<br>
32-
<form action="<?php echo $url; ?>">
17+
<form>
3318
<input type="hidden" name="test" value="1">
3419
Vous utilisez cette librairie dans le cadre :
3520
<ul style="list-style: none">
@@ -66,6 +51,5 @@
6651
<br>
6752
<input type="reset" name="btn_reset" value="Initialiser">
6853
<input type="button" name="btn_print" value="Imprimer" onclick="print(true);">
69-
<input type="submit" name="btn_submit" value="Envoyer">
7054
</form>
7155
</page>

src/Html2Pdf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function getVersionAsArray()
247247
return array(
248248
'major' => 5,
249249
'minor' => 2,
250-
'revision' => 7
250+
'revision' => 8
251251
);
252252
}
253253

0 commit comments

Comments
 (0)