Skip to content
Closed
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
3 changes: 3 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
php-version: ${{ matrix.php }}

- uses: actions/checkout@v7
# CI-only alias until TYPO3 accepts the security-fixed svg-sanitize ^1.0.
- run: composer require "enshrined/svg-sanitize:1.0.0 as 0.22.99" --dev --no-update --sort-packages --no-interaction
- run: composer update --with=typo3/cms-core:^${{ matrix.typo3 }}
- run: bash tests/typo3-svg-sanitizer.sh
- run: vendor/bin/grumphp run
- run: composer test
55 changes: 55 additions & 0 deletions tests/typo3-svg-sanitizer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

set -euo pipefail

# Exercise TYPO3's adapter against the actual security-fixed release, not its CI alias.
php <<'PHP'
<?php

require 'vendor/autoload.php';

function check(bool $condition, string $message): void
{
if (!$condition) {
throw new RuntimeException($message);
}
}

check(
Composer\InstalledVersions::getPrettyVersion('enshrined/svg-sanitize') === '1.0.0',
'Expected the actual security-fixed svg-sanitize 1.0.0 release'
);

$sanitizer = new TYPO3\CMS\Core\Resource\Security\SvgSanitizer();
$svg = '<svg xmlns="http://www.w3.org/2000/svg" onload="alert(1)">'
. '<rect id="safe" width="10" height="10"/>'
. '<image href="https://example.invalid/remote.svg"/></svg>';
$clean = $sanitizer->sanitizeContent($svg);
check(str_contains($clean, 'id="safe"'), 'Valid SVG content was removed');
check(!str_contains($clean, 'onload'), 'Event handler was not removed');
check(!str_contains($clean, 'example.invalid'), 'Remote reference was not removed');

$entity = '<!DOCTYPE svg [<!ENTITY Tab "#">]>'
. '<svg xmlns="http://www.w3.org/2000/svg"><a href="&Tab;javascript:alert(1)"/></svg>';
check($sanitizer->sanitizeContent($entity) === '', 'DTD entity bypass was not rejected');

$document = new DOMDocument();
check($document->loadXML($svg), 'Failed to load SVG fixture');
$node = $sanitizer->sanitizeNode($document->documentElement);
$cleanNode = $document->saveXML($node);
check(str_contains($cleanNode, 'id="safe"'), 'sanitizeNode removed valid content');
check(!str_contains($cleanNode, 'onload'), 'sanitizeNode retained an event handler');
check(!str_contains($cleanNode, 'example.invalid'), 'sanitizeNode retained a remote reference');

$file = tempnam(sys_get_temp_dir(), 'typo3-svg-');
check($file !== false, 'Failed to create temporary SVG fixture');
try {
check(file_put_contents($file, $svg) !== false, 'Failed to write SVG fixture');
$sanitizer->sanitizeFile($file);
check(file_get_contents($file) === $clean, 'sanitizeFile produced unexpected output');
} finally {
unlink($file);
}

echo "PASS: TYPO3 SVG content, node, file and DTD entity regression checks\n";
PHP
Loading