Skip to content

Commit 558fe81

Browse files
Merge branch '6.4' into 7.4
* 6.4: [Runtime] Fix CVE-2024-50340 patch bypass by gating argv on $_SERVER['QUERY_STRING']
2 parents 066e718 + be546fd commit 558fe81

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
@@ -223,6 +223,17 @@ public static function fileExcerptIntegrationProvider()
223223
];
224224
}
225225

226+
public function testFileExcerptEscapesNonPhpContents()
227+
{
228+
$file = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'xss.html';
229+
230+
$html = $this->getExtension()->fileExcerpt($file, 1);
231+
232+
$this->assertStringNotContainsString('<script>', $html);
233+
$this->assertStringContainsString('&lt;script&gt;alert(1)&lt;/script&gt;', $html);
234+
$this->assertStringContainsString('&amp; &quot;quoted&quot; &lt;tags&gt;', $html);
235+
}
236+
226237
public function testFormatFileFromTextIntegration()
227238
{
228239
$template = <<<'TWIG'

0 commit comments

Comments
 (0)