Explorar o código

Avoid duplicated enclosure titles (#9615)

Fix https://github.com/FreshRSS/FreshRSS/security/advisories/GHSA-pwpq-78jm-px4m
Alexandre Alapetite hai 1 día
pai
achega
5d81cd8832
Modificáronse 2 ficheiros con 35 adicións e 1 borrados
  1. 2 1
      app/Models/Entry.php
  2. 33 0
      tests/app/Models/EntryTest.php

+ 2 - 1
app/Models/Entry.php

@@ -296,7 +296,8 @@ class FreshRSS_Entry extends Minz_Model {
 
 
 			foreach ($thumbnails as $thumbnail) {
 			foreach ($thumbnails as $thumbnail) {
 				if (is_string($thumbnail) && \SimplePie\Misc::is_remote_uri($thumbnail)) {
 				if (is_string($thumbnail) && \SimplePie\Misc::is_remote_uri($thumbnail)) {
-					$content .= '<p><img class="enclosure-thumbnail" src="' . $thumbnail . '" alt="" title="' . $etitle . '" /></p>';
+					// No title here: it is output once with the enclosure itself below, not once more for each thumbnail
+					$content .= '<p><img class="enclosure-thumbnail" src="' . $thumbnail . '" alt="" /></p>';
 				}
 				}
 			}
 			}
 
 

+ 33 - 0
tests/app/Models/EntryTest.php

@@ -97,6 +97,39 @@ final class EntryTest extends \PHPUnit\Framework\TestCase {
 		self::assertStringContainsString('Hello', $html);
 		self::assertStringContainsString('Hello', $html);
 	}
 	}
 
 
+	public function test_content_doesNotRepeatEnclosureTitleForEachThumbnail(): void {
+		$title = str_repeat('&quot;', 2000);
+		$thumbnails = implode('', array_map(static fn(int $i): string => "<media:thumbnail url=\"https://example.net/$i.png\" />", range(1, 500)));
+		$rss = <<<XML
+			<?xml version="1.0" encoding="UTF-8"?>
+			<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
+				<channel>
+					<title>Feed</title>
+					<link>https://example.net/</link>
+					<item>
+						<title>Gallery</title>
+						<link>https://example.net/article</link>
+						<guid isPermaLink="false">gallery-001</guid>
+						<media:content url="https://example.net/video.mp4" type="video/mp4">
+							<media:title>{$title}</media:title>
+							{$thumbnails}
+						</media:content>
+					</item>
+				</channel>
+			</rss>
+			XML;
+
+		$entries = self::entriesFromRss($rss);
+		self::assertCount(1, $entries);
+		$html = $entries[0]->content();
+
+		// All the thumbnails are shown, and the title is kept for the enclosure itself
+		self::assertSame(500, substr_count($html, 'class="enclosure-thumbnail"'));
+		self::assertSame(1, substr_count($html, 'title="' . $title . '"'));
+		// But the size of the article is not the length of the title multiplied by the number of thumbnails
+		self::assertLessThan(5 * strlen($rss), strlen($html));
+	}
+
 	/** ZIP/JSON export/import */
 	/** ZIP/JSON export/import */
 	public function test_toGReaderFreshRssExportRoundTripsEncoding(): void {
 	public function test_toGReaderFreshRssExportRoundTripsEncoding(): void {
 		$feed = new FreshRSS_Feed('http://example.net/feed.xml', validate: false);
 		$feed = new FreshRSS_Feed('http://example.net/feed.xml', validate: false);