Don't construct appcast item if enclosure URL is invalid (#2317)

This commit is contained in:
Zorg authored and GitHub committed 2023-02-07 20:12:07 -08:00
1 parent 077d7228ba
commit 348c3a9658
5 files changed
+57 -4

No files matched your search

+4
View File
@@ -192,6 +192,7 @@
723ABFC5259D4CB300BDB4FA /* SUWKWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 723ABFC3259D4CB300BDB4FA /* SUWKWebView.m */; };
723AC010259DBDAA00BDB4FA /* SUWebViewCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 723AC00E259DBDAA00BDB4FA /* SUWebViewCommon.h */; };
723AC011259DBDAA00BDB4FA /* SUWebViewCommon.m in Sources */ = {isa = PBXBuildFile; fileRef = 723AC00F259DBDAA00BDB4FA /* SUWebViewCommon.m */; };
723AD12F29922B5F006BB02F /* test-dangerous-link.xml in Resources */ = {isa = PBXBuildFile; fileRef = 723AD12E29922B5F006BB02F /* test-dangerous-link.xml */; };
723B5DA71CF7AB0100365F95 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 723B5DA01CF7AB0100365F95 /* main.m */; };
723B5DA91CF7AB0100365F95 /* SPUDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 723B5DA31CF7AB0100365F95 /* SPUDownloader.m */; };
723B5DAA1CF7AB6A00365F95 /* SPUDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 723B5DA31CF7AB0100365F95 /* SPUDownloader.m */; };
@@ -1172,6 +1173,7 @@
723ABFC3259D4CB300BDB4FA /* SUWKWebView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUWKWebView.m; sourceTree = "<group>"; };
723AC00E259DBDAA00BDB4FA /* SUWebViewCommon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUWebViewCommon.h; sourceTree = "<group>"; };
723AC00F259DBDAA00BDB4FA /* SUWebViewCommon.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUWebViewCommon.m; sourceTree = "<group>"; };
723AD12E29922B5F006BB02F /* test-dangerous-link.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "test-dangerous-link.xml"; sourceTree = "<group>"; };
723B5D9F1CF7AB0100365F95 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Downloader/Info.plist; sourceTree = SOURCE_ROOT; };
723B5DA01CF7AB0100365F95 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = Downloader/main.m; sourceTree = SOURCE_ROOT; };
723B5DA21CF7AB0100365F95 /* SPUDownloader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPUDownloader.h; path = Downloader/SPUDownloader.h; sourceTree = SOURCE_ROOT; };
@@ -1832,6 +1834,7 @@
FA30773C24CBC295007BA37D /* testlocalizedreleasenotesappcast.xml */,
5A5DD41B249F0F4B0045EB3E /* test-relative-urls.xml */,
729F7EAB27366353004592DC /* test-links.xml */,
723AD12E29922B5F006BB02F /* test-dangerous-link.xml */,
5A5DD40324958AFF0045EB3E /* SUUpdateValidatorTest */,
);
path = Resources;
@@ -3100,6 +3103,7 @@
files = (
725B3A82263FBF0C0041AB8E /* testappcast_minimumAutoupdateVersion.xml in Resources */,
14958C6E19AEBC950061B14F /* signed-test-file.txt in Resources */,
723AD12F29922B5F006BB02F /* test-dangerous-link.xml in Resources */,
723EDC3F26885A8E000BCBA4 /* testappcast_channels.xml in Resources */,
720DC50427A51A6500DFF3EC /* testappcast_minimumAutoupdateVersionSkipping.xml in Resources */,
72AC6B2E1B9B218C00F62325 /* SparkleTestCodeSignApp.dmg in Resources */,
+4 -2
View File
@@ -470,8 +470,10 @@ static NSString *SUAppcastItemDeltaFromSparkleLocalesKey = @"SUAppcastItemDeltaF
if ([fileURL.scheme caseInsensitiveCompare:@"http"] == NSOrderedSame || [fileURL.scheme caseInsensitiveCompare:@"https"] == NSOrderedSame) {
_fileURL = fileURL;
} else {
SULog(SULogLevelError, @"File URLs must have a http or https URL scheme.");
_fileURL = nil;
if (error) {
*error = @"File URLs must have a http or https URL scheme";
}
return nil;
}
}
if (enclosure) {
+30
View File
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
<channel>
<title>For unit test only</title>
<item>
<title>Version 3.0</title>
<pubDate>Sat, 26 Jul 2014 15:20:12 +0000</pubDate>
<sparkle:releaseNotesLink>https://sparkle-project.org/notes/relnote-3.0.txt</sparkle:releaseNotesLink>
<sparkle:fullReleaseNotesLink>https://sparkle-project.org/fullnotes.txt</sparkle:fullReleaseNotesLink>
<link>https://sparkle-project.org</link>
<enclosure url="https://sparkle-project.org/release-3.0.zip" sparkle:version="3.0" length="1346234" />
</item>
<item>
<title>Version 2.0</title>
<pubDate>Sat, 26 Jul 2014 15:20:12 +0000</pubDate>
<sparkle:releaseNotesLink>http://sparkle-project.org/notes/relnote-2.0.txt</sparkle:releaseNotesLink>
<sparkle:fullReleaseNotesLink>http://sparkle-project.org/fullnotes.txt</sparkle:fullReleaseNotesLink>
<link>http://sparkle-project.org</link>
<enclosure url="http://sparkle-project.org/release-2.0.zip" sparkle:version="2.0" length="1346234" />
</item>
<item>
<title>Version 1.0</title>
<pubDate>Sat, 26 Jul 2014 15:20:12 +0000</pubDate>
<sparkle:releaseNotesLink>file://sparkle-project.org/notes/relnote-1.0.txt</sparkle:releaseNotesLink>
<sparkle:fullReleaseNotesLink>file://sparkle-project.org/fullnotes.txt</sparkle:fullReleaseNotesLink>
<link>file://sparkle-project.org</link>
<enclosure url="file://sparkle-project.org/release-1.0.zip" sparkle:version="1.0" length="1346234" />
</item>
</channel>
</rss>
+1 -1
View File
@@ -24,7 +24,7 @@
<sparkle:releaseNotesLink>file://sparkle-project.org/notes/relnote-1.0.txt</sparkle:releaseNotesLink>
<sparkle:fullReleaseNotesLink>file://sparkle-project.org/fullnotes.txt</sparkle:fullReleaseNotesLink>
<link>file://sparkle-project.org</link>
<enclosure url="file://sparkle-project.org/release-1.0.zip" sparkle:version="1.0" length="1346234" />
<enclosure url="https://sparkle-project.org/release-1.0.zip" sparkle:version="1.0" length="1346234" />
</item>
</channel>
</rss>
+18 -1
View File
@@ -934,7 +934,7 @@ class SUAppcastTest: XCTestCase {
XCTAssertEqual(nil, items[2].releaseNotesURL?.absoluteString)
XCTAssertEqual(nil, items[2].fullReleaseNotesURL?.absoluteString)
XCTAssertEqual(nil, items[2].infoURL?.absoluteString)
XCTAssertEqual(nil, items[2].fileURL?.absoluteString)
XCTAssertEqual("https://sparkle-project.org/release-1.0.zip", items[2].fileURL?.absoluteString)
} catch let err as NSError {
NSLog("%@", err)
@@ -972,4 +972,21 @@ class SUAppcastTest: XCTestCase {
}
}
func testDangerousLink() {
let testFile = Bundle(for: SUAppcastTest.self).path(forResource: "test-dangerous-link", ofType: "xml")!
let testData = NSData(contentsOfFile: testFile)!
do {
let baseURL: URL? = nil
let stateResolver = SPUAppcastItemStateResolver(hostVersion: "1.0", applicationVersionComparator: SUStandardVersionComparator.default, standardVersionComparator: SUStandardVersionComparator.default)
let _ = try SUAppcast(xmlData: testData as Data, relativeTo: baseURL, stateResolver: stateResolver)
XCTFail("Appcast creation should fail when encountering dangerous link")
} catch let err as NSError {
NSLog("Expected error: %@", err)
XCTAssertNotNil(err)
}
}
}