Skip to content

[HtmlSanitizer] Allow null for sanitizer option allowed_link_hosts and allowed_media_hosts #46849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,7 @@ private function addHttpClientRetrySection()
->integerNode('max_delay')->defaultValue(0)->min(0)->info('Max time in ms that a retry should ever be delayed (0 = infinite)')->end()
->floatNode('jitter')->defaultValue(0.1)->min(0)->max(1)->info('Randomness in percent (between 0 and 1) to apply to the delay')->end()
->end()
;
;
}

private function addMailerSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
Expand Down Expand Up @@ -2223,9 +2223,13 @@ private function addHtmlSanitizerSection(ArrayNodeDefinition $rootNode, callable
->info('Allows only a given list of schemes to be used in links href attributes.')
->scalarPrototype()->end()
->end()
->arrayNode('allowed_link_hosts')
->variableNode('allowed_link_hosts')
->info('Allows only a given list of hosts to be used in links href attributes.')
->scalarPrototype()->end()
->defaultValue(null)
->validate()
->ifTrue(function ($v) { return !\is_array($v) && null !== $v; })
->thenInvalid('The "allowed_link_hosts" parameter must be an array or null')
->end()
->end()
->booleanNode('allow_relative_links')
->info('Allows relative URLs to be used in links href attributes.')
Expand All @@ -2235,9 +2239,13 @@ private function addHtmlSanitizerSection(ArrayNodeDefinition $rootNode, callable
->info('Allows only a given list of schemes to be used in media source attributes (img, audio, video, ...).')
->scalarPrototype()->end()
->end()
->arrayNode('allowed_media_hosts')
->variableNode('allowed_media_hosts')
->info('Allows only a given list of hosts to be used in media source attributes (img, audio, video, ...).')
->scalarPrototype()->end()
->defaultValue(null)
->validate()
->ifTrue(function ($v) { return !\is_array($v) && null !== $v; })
->thenInvalid('The "allowed_media_hosts" parameter must be an array or null')
->end()
->end()
->booleanNode('allow_relative_medias')
->info('Allows relative URLs to be used in media source attributes (img, audio, video, ...).')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

$container->loadFromExtension('framework', [
'http_method_override' => false,
'html_sanitizer' => [
'sanitizers' => [
'custom_default' => null,
],
],
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<config xmlns="http://symfony.com/schema/dic/symfony" http-method-override="false">
<html-sanitizer>
<sanitizer name="custom_default"/>
</html-sanitizer>
</config>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
framework:
http_method_override: false
html_sanitizer:
sanitizers:
custom_default: ~
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,15 @@ static function ($call) {
$this->assertFalse($container->hasAlias(HtmlSanitizerInterface::class.' $default'));
}

public function testHtmlSanitizerDefaultNullAllowedLinkMediaHost()
{
$container = $this->createContainerFromFile('html_sanitizer_default_allowed_link_and_media_hosts');

$calls = $container->getDefinition('html_sanitizer.config.custom_default')->getMethodCalls();
$this->assertContains(['allowLinkHosts', [null], true], $calls);
$this->assertContains(['allowMediaHosts', [null], true], $calls);
}

public function testHtmlSanitizerDefaultConfig()
{
$container = $this->createContainerFromFile('html_sanitizer_default_config');
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy