Skip to content

Commit 45bc1f9

Browse files
committed
Escape iframe source in embed HTML
1 parent ebb18b8 commit 45bc1f9

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎src/Object/MediaObject.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ protected function buildIframe(): string {
405405

406406
$attributes = $this->buildAttributeString();
407407

408-
return sprintf('<iframe src="%s"%s></iframe>', $source, $attributes);
408+
return sprintf('<iframe src="%s"%s></iframe>', $this->esc($source), $attributes);
409409
}
410410

411411
/**

‎tests/MediaEmbedTest.php‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,26 @@ public function testEmbedCodeWithCustomAttributesAndParams(): void {
234234
$this->assertStringNotContainsString(' hidden', $code);
235235
}
236236

237+
public function testEmbedCodeEscapesIframeSource(): void {
238+
$MediaEmbed = new MediaEmbed();
239+
$MediaEmbed->addProviderConfig(new ProviderConfig(
240+
name: 'UnsafeProvider',
241+
website: 'https://unsafe.example.com',
242+
urlMatch: 'https://unsafe\\.example\\.com/video/([0-9]+)',
243+
embedWidth: 640,
244+
embedHeight: 360,
245+
iframePlayer: '//unsafe.example.com/embed/$2?foo=1&bar="quoted"',
246+
));
247+
248+
$Object = $MediaEmbed->parseUrl('https://unsafe.example.com/video/12345');
249+
$this->assertInstanceOf(MediaObject::class, $Object);
250+
251+
$code = $Object->getEmbedCode();
252+
253+
$this->assertStringContainsString('src="//unsafe.example.com/embed/12345?foo=1&amp;bar=&quot;quoted&quot;&amp;wmode=transparent"', $code);
254+
$this->assertStringNotContainsString('bar="quoted"', $code);
255+
}
256+
237257
/**
238258
* Test YouTube /live/ URL format
239259
*

0 commit comments

Comments
 (0)