diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 521083e5..d8e6a3b9 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -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 = ""; }; 723AC00E259DBDAA00BDB4FA /* SUWebViewCommon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUWebViewCommon.h; sourceTree = ""; }; 723AC00F259DBDAA00BDB4FA /* SUWebViewCommon.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUWebViewCommon.m; sourceTree = ""; }; + 723AD12E29922B5F006BB02F /* test-dangerous-link.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "test-dangerous-link.xml"; sourceTree = ""; }; 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 */, diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 1a7fea27..56d1bdc3 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -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) { diff --git a/Tests/Resources/test-dangerous-link.xml b/Tests/Resources/test-dangerous-link.xml new file mode 100644 index 00000000..02d0d96f --- /dev/null +++ b/Tests/Resources/test-dangerous-link.xml @@ -0,0 +1,30 @@ + + + + For unit test only + + Version 3.0 + Sat, 26 Jul 2014 15:20:12 +0000 + https://sparkle-project.org/notes/relnote-3.0.txt + https://sparkle-project.org/fullnotes.txt + https://sparkle-project.org + + + + Version 2.0 + Sat, 26 Jul 2014 15:20:12 +0000 + http://sparkle-project.org/notes/relnote-2.0.txt + http://sparkle-project.org/fullnotes.txt + http://sparkle-project.org + + + + Version 1.0 + Sat, 26 Jul 2014 15:20:12 +0000 + file://sparkle-project.org/notes/relnote-1.0.txt + file://sparkle-project.org/fullnotes.txt + file://sparkle-project.org + + + + diff --git a/Tests/Resources/test-links.xml b/Tests/Resources/test-links.xml index 02d0d96f..8bddbd10 100644 --- a/Tests/Resources/test-links.xml +++ b/Tests/Resources/test-links.xml @@ -24,7 +24,7 @@ file://sparkle-project.org/notes/relnote-1.0.txt file://sparkle-project.org/fullnotes.txt file://sparkle-project.org - + diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index be98819a..b83e548e 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -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) + } + } }