Use timeline copy in iOS image viewer only if correctly signed.

This commit is contained in:
Brent Simmons committed 2026-10-29 12:30:00 -07:00
1 parent 814e7d0d89
commit 60640b235e
2 files changed
+6 -7

No files matched your search

+4 -4
View File
@@ -593,8 +593,7 @@ private struct ImageClickMessage: Codable {
let width: Float
let height: Float
let imageTitle: String?
let imageURL: String
let isTimelineImage: Bool // Served from the timeline’s copy
let imageURL: String // The <img>’s src, which may be a routed timeline image
}
// MARK: Private
@@ -757,8 +756,9 @@ private extension WebViewController {
imageDownloadTask?.cancel()
imageDownloadTask = Task { [weak self] in
var data: Data?
if clickMessage.isTimelineImage {
data = try? await ArticleThumbnailFinder.shared.fullSizeImageData(url: clickMessage.imageURL, articleTitle: nil)
// Only a correctly signed routed URL uses the timeline’s copy, so page content can’t claim one.
if imageURL.scheme?.caseInsensitiveCompare(ArticleRenderer.articleImageScheme) == .orderedSame, let timelineImageURL = ArticleImageSchemeHandler.imageURL(imageURL) {
data = try? await ArticleThumbnailFinder.shared.fullSizeImageData(url: timelineImageURL, articleTitle: nil)
} else {
data = try? await Downloader.shared.download(imageURL, userAgentStyle: .browser).data
}
+2 -3
View File
@@ -37,15 +37,14 @@ class ImageViewer {
const rect = this.img.getBoundingClientRect();
// Instead of trying to convert to canvas (which fails with CORS),
// send the original image src URL
// send the image's src URL. Swift checks a routed timeline image's signature.
const message = {
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height,
imageTitle: this.img.title,
imageURL: this.img.dataset.nnwSrc || this.img.src,
isTimelineImage: this.img.hasAttribute("data-nnw-src"),
imageURL: this.img.src,
};
var jsonMessage = JSON.stringify(message);