Skip to content

Commit 14188e7

Browse files
Merge branch '8.0' into 8.1
* 8.0: [Runtime] Fix CVE-2024-50340 patch bypass by gating argv on $_SERVER['QUERY_STRING']
2 parents 86961c3 + 1d92c5e commit 14188e7

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

Profiler/CodeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function fileExcerpt(string $file, int $line, int $srcContext = 3): ?stri
126126
$contents = file_get_contents($file);
127127

128128
if (!str_contains($contents, '<?php') && !str_contains($contents, '<?=')) {
129-
$lines = explode("\n", $contents);
129+
$lines = explode("\n", htmlspecialchars($contents, \ENT_QUOTES | \ENT_SUBSTITUTE, $this->charset));
130130

131131
if (0 > $srcContext) {
132132
$srcContext = \count($lines);

Tests/Fixtures/xss.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<script>alert(1)</script>
2+
& "quoted" <tags>

Tests/Profiler/CodeExtensionTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,17 @@ public static function fileExcerptIntegrationProvider()
217217
];
218218
}
219219

220+
public function testFileExcerptEscapesNonPhpContents()
221+
{
222+
$file = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'xss.html';
223+
224+
$html = $this->getExtension()->fileExcerpt($file, 1);
225+
226+
$this->assertStringNotContainsString('<script>', $html);
227+
$this->assertStringContainsString('&lt;script&gt;alert(1)&lt;/script&gt;', $html);
228+
$this->assertStringContainsString('&amp; &quot;quoted&quot; &lt;tags&gt;', $html);
229+
}
230+
220231
public function testFormatFileFromTextIntegration()
221232
{
222233
$template = <<<'TWIG'

0 commit comments

Comments
 (0)