Skip to content

Commit 035be66

Browse files
committed
Content: Updated tests and CSP usage of content script setting
Updates CSP to use new content_filtering option. Splits out content filtering tests to their own class. Updated tests where needed to adapt to changes.
1 parent 227027f commit 035be66

File tree

7 files changed

+368
-354
lines changed

7 files changed

+368
-354
lines changed

app/Entities/Tools/PageContent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ protected function getContentCacheKey(string $html): string
339339
{
340340
$contentHash = md5($html);
341341
$contentId = $this->page->id;
342-
$contentTime = $this->page->updated_at->timestamp;
342+
$contentTime = $this->page->updated_at?->timestamp ?? time();
343343
$appVersion = AppVersion::get();
344344
return "page-content-cache::{$appVersion}::{$contentId}::{$contentTime}::{$contentHash}";
345345
}

app/Theming/CustomHtmlHeadContentProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function forExport(): string
4141
$hash = md5($content);
4242

4343
return $this->cache->remember('custom-head-export:' . $hash, 86400, function () use ($content) {
44-
$config = new HtmlContentFilterConfig(filterOutNonContentElements: false);
44+
$config = new HtmlContentFilterConfig(filterOutNonContentElements: false, useAllowListFilter: false);
4545
return (new HtmlContentFilter($config))->filterString($content);
4646
});
4747
}

app/Util/ConfiguredHtmlPurifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function setConfig(HTMLPurifier_Config $config): void
6262
$config->set('Attr.EnableID', true);
6363
$config->set('Attr.ID.HTML5', true);
6464
$config->set('Output.FixInnerHTML', false);
65-
$config->set('URI.SafeIframeRegexp', '%^(http://|https://)%');
65+
$config->set('URI.SafeIframeRegexp', '%^(http://|https://|//)%');
6666
$config->set('URI.AllowedSchemes', [
6767
'http' => true,
6868
'https' => true,

app/Util/CspService.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function allowedIFrameHostsConfigured(): bool
6565
*/
6666
protected function getScriptSrc(): string
6767
{
68-
if (config('app.allow_content_scripts')) {
68+
if ($this->scriptFilteringDisabled()) {
6969
return '';
7070
}
7171

@@ -108,7 +108,7 @@ protected function getFrameSrc(): string
108108
*/
109109
protected function getObjectSrc(): string
110110
{
111-
if (config('app.allow_content_scripts')) {
111+
if ($this->scriptFilteringDisabled()) {
112112
return '';
113113
}
114114

@@ -124,6 +124,11 @@ protected function getBaseUri(): string
124124
return "base-uri 'self'";
125125
}
126126

127+
protected function scriptFilteringDisabled(): bool
128+
{
129+
return !HtmlContentFilterConfig::fromConfigString(config('app.content_filtering'))->filterOutJavaScript;
130+
}
131+
127132
protected function getAllowedIframeHosts(): array
128133
{
129134
$hosts = config('app.iframe_hosts') ?? '';

0 commit comments

Comments
 (0)