From 0187b15c8eef702ba282ae0509b1b195afe7a8af Mon Sep 17 00:00:00 2001 From: ImperfectBlu <124731356+lordmarrik@users.noreply.github.com> Date: Sun, 11 Oct 2026 14:36:09 -0400 Subject: [PATCH] Sanitizer: block data: URI scheme while keeping data:image for images (#9417) * Sanitizer: block data: URI scheme, keep data:image for images FreshRSS_SimplePieCustom only disallowed the `javascript` scheme, so `data:text/html,...` URIs in feed content survived sanitization on , ', 'src="data:']; + yield 'data:text/html URL in image' => ['', 'src="data:']; + yield 'data:image URL in link' => ['click', 'href="data:']; } public static function test_sanitizeHTML_whenSafeHtml_keepsAllowedTags(): void { @@ -92,4 +96,19 @@ final class SimplePieCustomTest extends \PHPUnit\Framework\TestCase { yield 'double unclosed tag' => [' x', 10, 'x']; yield 'triple unclosed tag' => [' y', 20, 'y']; } + + /** + * Inline `data:image/...` URIs are inert in `` and widely used by feeds, so they must survive + * while `data:` is blocked on navigational/framing attributes (see provideMaliciousHtml()). + */ + public static function test_sanitizeHTML_whenDataImageUri_keepsItOnImageElements(): void { + $png = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='; + self::assertSame('', FreshRSS_SimplePieCustom::sanitizeHTML('')); + self::assertStringContainsString('poster="' . $png . '"', FreshRSS_SimplePieCustom::sanitizeHTML('')); + } + + public static function test_sanitizeHTML_whenDisallowedScheme_prefixesUnsafe(): void { + $result = FreshRSS_SimplePieCustom::sanitizeHTML('click'); + self::assertStringContainsString('href="unsafe:data:text/html,x"', $result); + } }