diff --git a/src/podcasts/publication.rs b/src/podcasts/publication.rs index 4da7fc1..8376773 100644 --- a/src/podcasts/publication.rs +++ b/src/podcasts/publication.rs @@ -381,10 +381,10 @@ pub fn confirmations_path(db_path: &Path) -> PathBuf { /// URL this device fetches, `id_feed_url` the origin URL the podcast id was /// derived from. Bounded to the card limits. /// -/// The artwork and web page URLs are left out when they look private -/// themselves (`feed_url_privacy_warning`) or when the feed URLs do: member -/// feeds serve signed artwork and item links, and the share dialog shows -/// the feed URLs only. +/// The artwork and web page URLs are left out when they look like they +/// carry an access key themselves ([`looks_private`]) or when the feed URLs +/// look private: member feeds serve signed artwork and item links, and the +/// share dialog shows the feed URLs only. fn catalog_card( summary: &PodcastSummary, subscription: &SubscriptionRecord, @@ -422,13 +422,27 @@ fn catalog_card( } /// An artwork or web page URL that must not be published: it carries what -/// looks like an access key (the feed URL rules), or it is not a plain -/// http(s) URL those rules can check. +/// looks like an access key, or it is not a plain http(s) URL the rules can +/// check. +/// +/// The feed URL rules apply except the random-looking path segment: public +/// podcast hosts and CDNs name artwork and pages by UUIDs and content +/// hashes, so that rule would drop the artwork of most public podcasts. +/// Signed and tokenized artwork carries its key in the query, which the +/// other rules catch (user info is refused by `FeedUrl::parse`), and a +/// member feed's artwork is left out with its feed anyway. +/// `feed_url_privacy_warning` checks the path last, so a path warning means +/// no other rule matched. fn looks_private(url: &str) -> bool { - FeedUrl::parse(url).map_or(true, |url| feed_url_privacy_warning(&url).is_some()) + FeedUrl::parse(url).map_or(true, |url| { + !matches!( + feed_url_privacy_warning(&url), + None | Some(FeedUrlPrivacyWarning::HighEntropyPathSegment { .. }) + ) + }) } -/// The card [`share_states`] would publish for `podcast_id` (whether or not +/// The card [`share_plan`] would publish for `podcast_id` (whether or not /// it is shared yet), for the share confirmation. `None` when there is no /// subscription. pub fn share_card(store: &PodcastStore, podcast_id: &PodcastId) -> Result> { diff --git a/src/podcasts/publication_tests.rs b/src/podcasts/publication_tests.rs index b5f62e0..858ebc6 100644 --- a/src/podcasts/publication_tests.rs +++ b/src/podcasts/publication_tests.rs @@ -496,6 +496,56 @@ fn cards_leave_out_artwork_and_links_that_look_private() { ); assert!(card.privacy_warnings().is_empty()); + // Public hosts name artwork and pages by UUIDs and content hashes in + // the path: kept (a key in the query is not). + for public in [ + "https://megaphone.imgix.net/podcasts/1f2e3d4c-5b6a-11ee-8c99-0242ac120002/image/art.jpg", + "https://image.simplecastcdn.com/images/4c3b2a19-8d7e-4f6a-b5c4-d3e2f1a0b9c8/3a2b1c0d-9e8f-4a7b-6c5d-4e3f2a1b0c9d/3000x3000/art.jpg", + "https://is1-ssl.mzstatic.com/image/thumb/Podcasts126/v4/0a/1b/2c/0a1b2c3d-4e5f-6a7b-8c9d-0e1f2a3b4c5d/mza_1234567890123456789.jpg/600x600bb.jpg", + "https://d3t3ozftmdmh3i.cloudfront.net/production/podcast_uploaded/1234567/1234567-1600000000000-0123456789abc.jpg", + ] { + assert!( + FeedUrl::parse(public) + .ok() + .and_then(|url| music_dht::podcast_dht::feed_url_privacy_warning(&url)) + .is_some(), + "the feed URL rules flag {public}" + ); + let show = device.subscribe_meta( + &store, + &PodcastMeta { + feed_url: FeedUrl::parse(&format!( + "https://feeds.example.test/{}.xml", + public.len() + )) + .unwrap(), + ..meta(SHOW_URL, public, public) + }, + ); + let card = share_card(&store, &show).unwrap().unwrap(); + assert_eq!(card.image_url.as_deref(), Some(public)); + assert_eq!(card.link.as_deref(), Some(public)); + } + for signed in [ + "https://cdn.example.test/art.jpg?sig=Zm9vYmFyYmF6cXV4cXV1eDEyMzQ1Njc4OQ", + "https://www.patreon.com/file?h=1234&i=5678", + "ftp://cdn.example.test/art.jpg", + ] { + let show = device.subscribe_meta( + &store, + &PodcastMeta { + feed_url: FeedUrl::parse(&format!( + "https://feeds.example.test/signed-{}.xml", + signed.len() + )) + .unwrap(), + ..meta(SHOW_URL, signed, signed) + }, + ); + let card = share_card(&store, &show).unwrap().unwrap(); + assert_eq!((card.image_url, card.link), (None, None), "{signed}"); + } + // A member feed (its URL needs the dialog): artwork and page are left // out whatever they look like, the dialog shows the feed URLs only. let secret = device.subscribe_meta(