Skip to content

Commit

Permalink
[TASK] Add csp support for v13
Browse files Browse the repository at this point in the history
  • Loading branch information
ayacoo committed Sep 27, 2024
1 parent 535bece commit fd9edea
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Classes/Helper/SoundcloudHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getPreviewImage(File $file)
$previewImageUrl = trim($properties['soundcloud_thumbnail_url'] ?? '');

// get preview from soundcloud
if ($previewImageUrl !== '') {
if ($previewImageUrl === '') {
$oEmbed = $this->getOEmbedData($this->getOnlineMediaId($file));
$previewImageUrl = $oEmbed['thumbnail_url'];
}
Expand Down
34 changes: 34 additions & 0 deletions Configuration/ContentSecurityPolicies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

use TYPO3\CMS\Core\Security\ContentSecurityPolicy\Directive;
use TYPO3\CMS\Core\Security\ContentSecurityPolicy\Mutation;
use TYPO3\CMS\Core\Security\ContentSecurityPolicy\MutationCollection;
use TYPO3\CMS\Core\Security\ContentSecurityPolicy\MutationMode;
use TYPO3\CMS\Core\Security\ContentSecurityPolicy\Scope;
use TYPO3\CMS\Core\Security\ContentSecurityPolicy\SourceScheme;
use TYPO3\CMS\Core\Security\ContentSecurityPolicy\UriValue;
use TYPO3\CMS\Core\Type\Map;

return Map::fromEntries([
Scope::backend(),

new MutationCollection(
// The csp extension is required for images in the PreviewRenderer when active
new Mutation(
MutationMode::Extend,
Directive::ImgSrc,
SourceScheme::data,
new UriValue('*.sndcdn.com'),
),

// The csp extension is required for the IFrame in the info window
new Mutation(
MutationMode::Extend,
Directive::FrameSrc,
SourceScheme::data,
new UriValue('*.soundcloud.com'),
),
),
]);
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ with `$GLOBALS['TCA']['tt_content']['types']['textmedia']['previewRenderer'] = \

Documentation: https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/ContentElements/CustomBackendPreview.html

### 3.3 Content security policy

If CSP is activated in the backend, policies will be automatically added.
To do this, the file Configuration/ContentSecurityPolicies.php is used.

If CSP is to be extended for the frontend, the configuration can be added
in a site package extension or in the global csp.yml

Take a look at the current documentation:
https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/ContentSecurityPolicy/Index.html


## 4 Administration corner

### 4.1 Versions and support
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
],
"require": {
"php": ">=8.2 < 8.4",
"typo3/cms-core": "^13.1"
"typo3/cms-core": "^13.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.49.0",
"friendsofphp/php-cs-fixer": "^3.57.0",
"helmich/typo3-typoscript-lint": "^3.1.0",
"phpstan/extension-installer": "^1.3.1",
"phpstan/phpstan": "^1.11",
Expand Down

0 comments on commit fd9edea

Please sign in to comment.