diff --git a/.github/workflows/tasks.yml b/.github/workflows/tasks.yml index 98cf687..41800db 100644 --- a/.github/workflows/tasks.yml +++ b/.github/workflows/tasks.yml @@ -23,8 +23,11 @@ jobs: key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: | ${{ runner.os }}-${{ matrix.php }}-composer- + # 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 require typo3/cms-frontend="^${{ matrix.typo3 }}" --dev - run: composer install --no-interaction --no-progress + - run: bash tests/typo3-svg-sanitizer.sh - run: ./vendor/bin/grumphp run --ansi - run: composer test diff --git a/tests/typo3-svg-sanitizer.sh b/tests/typo3-svg-sanitizer.sh new file mode 100644 index 0000000..9ae3fdd --- /dev/null +++ b/tests/typo3-svg-sanitizer.sh @@ -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' +' + . '' + . ''; +$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 = ']>' + . ''; +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