Add <sparkle:bundleIdentifier> on appcast for signed feeds (#2954)

This commit is contained in:
Zorg authored and GitHub committed 2026-11-15 15:17:39 -08:00
1 parent b390cd147f
commit 3df8c96fcb
15 files changed
+123 -4

No files matched your search

+4
View File
@@ -141,6 +141,7 @@
720E217B1D0D00BF003A311C /* SPUUpdaterCycle.h in Headers */ = {isa = PBXBuildFile; fileRef = 720E21791D0D00BF003A311C /* SPUUpdaterCycle.h */; };
720E217C1D0D00BF003A311C /* SPUUpdaterCycle.m in Sources */ = {isa = PBXBuildFile; fileRef = 720E217A1D0D00BF003A311C /* SPUUpdaterCycle.m */; };
7210C7681B9A9A1500EB90AC /* SUUnarchiverTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */; };
7212F16330A0311500BC9C7D /* testappcast_bundleIdentifiers.xml in Resources */ = {isa = PBXBuildFile; fileRef = 7210219630A0311500CA3DBD /* testappcast_bundleIdentifiers.xml */; };
72162B081C82C9600013C1C5 /* SULocalizations.h in Headers */ = {isa = PBXBuildFile; fileRef = 72162B071C82C9600013C1C5 /* SULocalizations.h */; };
721BC20E1D1CDE55002BC71E /* SPULocalCacheDirectory.h in Headers */ = {isa = PBXBuildFile; fileRef = 721BC20C1D1CDE55002BC71E /* SPULocalCacheDirectory.h */; };
721BC20F1D1CDE55002BC71E /* SPULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SPULocalCacheDirectory.m */; };
@@ -1039,6 +1040,7 @@
720DC50527A62CDC00DFF3EC /* testappcast_minimumAutoupdateVersionSkipping2.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = testappcast_minimumAutoupdateVersionSkipping2.xml; sourceTree = "<group>"; };
720E21791D0D00BF003A311C /* SPUUpdaterCycle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUpdaterCycle.h; sourceTree = "<group>"; };
720E217A1D0D00BF003A311C /* SPUUpdaterCycle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUUpdaterCycle.m; sourceTree = "<group>"; };
7210219630A0311500CA3DBD /* testappcast_bundleIdentifiers.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = testappcast_bundleIdentifiers.xml; sourceTree = "<group>"; };
7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUUnarchiverTest.swift; sourceTree = "<group>"; };
7214B8851D45AD9A00CB5CED /* SPUInstallationType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUInstallationType.h; sourceTree = "<group>"; };
72162B071C82C9600013C1C5 /* SULocalizations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SULocalizations.h; sourceTree = "<group>"; };
@@ -1825,6 +1827,7 @@
725EA4B13027D2AF0041BFA6 /* test-package-update.xml */,
72C56E212F04C28B0005A484 /* testreleasenotes.html */,
5A5DD40324958AFF0045EB3E /* SUUpdateValidatorTest */,
7210219630A0311500CA3DBD /* testappcast_bundleIdentifiers.xml */,
);
path = Resources;
sourceTree = "<group>";
@@ -3117,6 +3120,7 @@
72CCDEBE27421FD500B53718 /* SparkleTestCodeSignApp_bad_header.zip in Resources */,
726FC0362C1E787A00177986 /* SparkleTestCodeSignApp.aar in Resources */,
722545B626805FF80036465C /* testappcast_info_updates.xml in Resources */,
7212F16330A0311500BC9C7D /* testappcast_bundleIdentifiers.xml in Resources */,
723414172EBFB482009727E0 /* testappcast_arm64HardwareRequirement.xml in Resources */,
7202DC9A269ABD3500737EC4 /* testappcast_phasedRollout.xml in Resources */,
72C6F2DB303BE56100D39EF2 /* SparkleTestCodeSignApp.license.no-text.dmg in Resources */,
+14 -1
View File
@@ -73,6 +73,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
BOOL _loggedATSWarning;
BOOL _loggedNoSecureKeyWarning;
BOOL _loggedUpdateSecurityPolicyWarning;
BOOL _loggedFeedBundleIdentifierWarning;
BOOL _updatingMainBundle;
}
@@ -379,14 +380,26 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
return NO;
}
} else if (_host.requiresFeedBundleIdentifier) {
if (error != NULL) {
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInvalidUpdaterError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"For security reasons, %@ needs to also be enabled if %@ is enabled for %@. Visit Sparkle's documentation for more information: https://sparkle-project.org/documentation/customization/", SURequireSignedFeedKey, SURequireFeedBundleIdentifierKey, hostName] }];
}
return NO;
}
if (_updatingMainBundle) {
if (!_loggedUpdateSecurityPolicyWarning && mainBundleHost.hasUpdateSecurityPolicy) {
SULog(SULogLevelDefault, @"Warning: %@ has a custom NSUpdateSecurityPolicy in its Info.plist. This may cause issues when installing updates. Please consider removing this key for your builds using Sparkle if you do not really require a custom update security policy.", hostName);
_loggedUpdateSecurityPolicyWarning = YES;
}
if (!_loggedFeedBundleIdentifierWarning && requiresSignedFeed && ![_host boolForInfoDictionaryKey:SURequireFeedBundleIdentifierKey]) {
SULog(SULogLevelDefault, @"Warning: %@ is enabled but %@ is not enabled for %@. For increased security, please consider enabling %@ and adding a %@ element to your signed feed. Visit Sparkle's documentation for more information: https://sparkle-project.org/documentation/#3-segue-for-security-concerns.", SURequireSignedFeedKey, SURequireFeedBundleIdentifierKey, hostName, SURequireFeedBundleIdentifierKey, SUAppcastElementBundleIdentifier);
_loggedFeedBundleIdentifierWarning = YES;
}
}
return YES;
+2
View File
@@ -30,6 +30,8 @@ NS_ASSUME_NONNULL_BEGIN
- (SUAppcast *)copyByFilteringItems:(BOOL (^)(SUAppcastItem *))filterBlock;
@property (readonly, nonatomic, copy) NSSet<NSString *> *bundleIdentifiers;
@end
NS_ASSUME_NONNULL_END
+24
View File
@@ -21,10 +21,17 @@
#include "AppKitPrevention.h"
@interface SUAppcast ()
@property (readonly, nonatomic, copy) NSSet<NSString *> *bundleIdentifiers;
@end
@implementation SUAppcast
@synthesize items = _items;
@synthesize signingValidationStatus = _signingValidationStatus;
@synthesize bundleIdentifiers = _bundleIdentifiers;
- (nullable instancetype)initWithXMLData:(NSData *)xmlData relativeToURL:(NSURL * _Nullable)relativeURL stateResolver:(SPUAppcastItemStateResolver *)stateResolver signingValidationStatus:(SPUAppcastSigningValidationStatus)signingValidationStatus error:(NSError * __autoreleasing *)error
{
@@ -86,6 +93,22 @@
return nil;
}
NSArray *channelNodes = [document nodesForXPath:@"/rss/channel/*" error:errorp];
if (nil == channelNodes) {
return nil;
}
NSMutableSet<NSString *> *bundleIdentifiers = [NSMutableSet set];
for (NSXMLNode *channelNode in channelNodes) {
if ([[self sparkleNamespacedNameOfNode:channelNode] isEqualToString:SUAppcastElementBundleIdentifier]) {
NSString *bundleIdentifier = [channelNode.stringValue stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
if (bundleIdentifier.length > 0) {
[bundleIdentifiers addObject:bundleIdentifier];
}
}
}
_bundleIdentifiers = [bundleIdentifiers copy];
NSArray *xmlItems = [document nodesForXPath:@"/rss/channel/item" error:errorp];
if (nil == xmlItems) {
return nil;
@@ -288,6 +311,7 @@
other->_items = newItems;
other->_signingValidationStatus = _signingValidationStatus;
other->_bundleIdentifiers = _bundleIdentifiers;
return other;
}
+12 -1
View File
@@ -232,7 +232,18 @@
return;
}
if (appcastSigningValidationStatus == SPUAppcastSigningValidationStatusSucceeded && _host.requiresFeedBundleIdentifier) {
NSString *hostBundleIdentifier = _host.bundle.bundleIdentifier;
if (hostBundleIdentifier == nil || ![loadedAppcast.bundleIdentifiers containsObject:hostBundleIdentifier]) {
NSError *bundleIdentifierError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"The update feed is rejected because %@ is enabled and no %@ element in the feed matches the bundle identifier %@.", SURequireFeedBundleIdentifierKey, SUAppcastElementBundleIdentifier, hostBundleIdentifier] }];
[delegate didFailToFetchAppcastWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedStringFromTableInBundle(@"An error occurred while parsing the update feed.", SPARKLE_TABLE, SUSparkleBundle(), nil), NSUnderlyingErrorKey: bundleIdentifierError }]];
return;
}
}
// Now process the loaded appcast and find a suitable update item
[delegate didFinishLoadingAppcast:loadedAppcast];
+2
View File
@@ -47,6 +47,7 @@ extern NSString *const SUPublicDSAKeyKey;
extern NSString *const SUPublicDSAKeyFileKey;
extern NSString *const SUPublicEDKeyKey;
extern NSString *const SURequireSignedFeedKey;
extern NSString *const SURequireFeedBundleIdentifierKey;
extern NSString *const SUVerifyUpdateBeforeExtractionKey;
extern NSString *const SUDisableFeedCacheValidationKey;
extern NSString *const SUAutomaticallyUpdateKey;
@@ -83,6 +84,7 @@ extern NSString *const SUAppcastAttributeLength;
extern NSString *const SUAppcastElementVersion;
extern NSString *const SUAppcastElementShortVersionString;
extern NSString *const SUAppcastElementBundleIdentifier;
extern NSString *const SUAppcastElementCriticalUpdate;
extern NSString *const SUAppcastElementDeltas;
extern NSString *const SUAppcastElementMinimumAutoupdateVersion;
+2
View File
@@ -34,6 +34,7 @@ NSString *const SUPublicDSAKeyKey = @"SUPublicDSAKey";
NSString *const SUPublicDSAKeyFileKey = @"SUPublicDSAKeyFile";
NSString *const SUPublicEDKeyKey = @"SUPublicEDKey";
NSString *const SURequireSignedFeedKey = @"SURequireSignedFeed";
NSString *const SURequireFeedBundleIdentifierKey = @"SURequireFeedBundleIdentifier";
NSString *const SUVerifyUpdateBeforeExtractionKey = @"SUVerifyUpdateBeforeExtraction";
NSString *const SUDisableFeedCacheValidationKey = @"SUDisableFeedCacheValidation";
NSString *const SUAutomaticallyUpdateKey = @"SUAutomaticallyUpdate";
@@ -72,6 +73,7 @@ NSString *const SUAppcastAttributeLength = @"sparkle:length";
NSString *const SUAppcastElementVersion = SUAppcastAttributeVersion;
NSString *const SUAppcastElementShortVersionString = SUAppcastAttributeShortVersionString;
NSString *const SUAppcastElementBundleIdentifier = @"sparkle:bundleIdentifier";
NSString *const SUAppcastElementCriticalUpdate = @"sparkle:criticalUpdate";
NSString *const SUAppcastElementDeltas = @"sparkle:deltas";
NSString *const SUAppcastElementMinimumAutoupdateVersion = @"sparkle:minimumAutoupdateVersion";
+1
View File
@@ -44,6 +44,7 @@ SUHostDefinitionAttribute
@property (nonatomic, readonly) BOOL hasUpdateSecurityPolicy;
@property (nonatomic, readonly) BOOL requiresSignedAppcast;
@property (nonatomic, readonly) BOOL requiresFeedBundleIdentifier;
- (nullable id)objectForInfoDictionaryKey:(NSString *)key ofClass:(Class)aClass;
- (nullable NSNumber *)boolNumberForInfoDictionaryKey:(NSString *)key;
+5
View File
@@ -268,6 +268,11 @@ static void *SUHostObservableContext = &SUHostObservableContext;
return [self boolForInfoDictionaryKey:SURequireSignedFeedKey];
}
- (BOOL)requiresFeedBundleIdentifier
{
return [self boolForInfoDictionaryKey:SURequireFeedBundleIdentifierKey];
}
- (SUPublicKeys *)publicKeys
{
return [[SUPublicKeys alloc] initWithEd:[self publicEDKey]
@@ -36,6 +36,8 @@
<true/>
<key>SURequireSignedFeed</key>
<true/>
<key>SURequireFeedBundleIdentifier</key>
<true/>
<key>SUVerifyUpdateBeforeExtraction</key>
<true/>
<key>_SUEnableDebugUpdateCheckIntervals</key>
+1
View File
@@ -7,6 +7,7 @@ IMPORTANT: This file must be re-signed if modifications are made to this file! T
<title>Sparkle Test App Changelog</title>
<description>Most recent changes with links to updates.</description>
<language>en</language>
<sparkle:bundleIdentifier>org.sparkle-project.SparkleTestApp</sparkle:bundleIdentifier>
<item>
<title>Version 3.1</title>
<sparkle:version>3.1</sparkle:version>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
<channel>
<title>Test</title>
<sparkle:bundleIdentifier>com.example.first</sparkle:bundleIdentifier>
<sparkle:bundleIdentifier>
com.example.second
</sparkle:bundleIdentifier>
<sparkle:bundleIdentifier></sparkle:bundleIdentifier>
<item>
<title>Version 2.0</title>
<enclosure url="http://example.com/test.zip" sparkle:version="2.0" length="1" type="application/octet-stream" sparkle:edSignature="test" />
</item>
</channel>
</rss>
+21
View File
@@ -1208,4 +1208,25 @@ class SUAppcastTest: XCTestCase {
XCTFail("Appcast creation should have passed, dropping only the rejected package item")
}
}
func testParseAppcastBundleIdentifiers() throws {
let versionComparator = SUStandardVersionComparator.default
let stateResolver = SPUAppcastItemStateResolver(hostVersion: "1.0", applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator)
let testURL = Bundle(for: SUAppcastTest.self).url(forResource: "testappcast_bundleIdentifiers", withExtension: "xml")!
let testData = try Data(contentsOf: testURL)
let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver, signingValidationStatus: .succeeded)
XCTAssertEqual(appcast.bundleIdentifiers, ["com.example.first", "com.example.second"])
XCTAssertEqual(appcast.items.count, 1)
let filteredAppcast = appcast.copy(byFilteringItems: { _ in false })
XCTAssertEqual(filteredAppcast.bundleIdentifiers, ["com.example.first", "com.example.second"])
let testURLWithoutBundleIdentifiers = Bundle(for: SUAppcastTest.self).url(forResource: "testappcast", withExtension: "xml")!
let testDataWithoutBundleIdentifiers = try Data(contentsOf: testURLWithoutBundleIdentifiers)
let appcastWithoutBundleIdentifiers = try SUAppcast(xmlData: testDataWithoutBundleIdentifiers, relativeTo: nil, stateResolver: stateResolver, signingValidationStatus: .succeeded)
XCTAssertEqual(appcastWithoutBundleIdentifiers.bundleIdentifiers, [])
}
}
+4 -1
View File
@@ -78,6 +78,7 @@ class ArchiveItem: CustomStringConvertible {
let publicEdKey: Data?
let supportsDSA: Bool
let requiresSignedAppcast: Bool
let bundleIdentifier: String?
let archiveFileAttributes: [FileAttributeKey: Any]
var deltas: [DeltaUpdate]
@@ -174,11 +175,12 @@ class ArchiveItem: CustomStringConvertible {
}
}
init(version: String, shortVersion: String?, feedURL: URL?, requiresSignedAppcast: Bool, minimumSystemVersion: String?, hardwareRequirements: String?, frameworkVersion: String?, sparkleExecutableFileSize: Int?, sparkleLocales: String?, publicEdKey: String?, supportsDSA: Bool, appPath: URL, archivePath: URL) throws {
init(version: String, shortVersion: String?, feedURL: URL?, requiresSignedAppcast: Bool, bundleIdentifier: String?, minimumSystemVersion: String?, hardwareRequirements: String?, frameworkVersion: String?, sparkleExecutableFileSize: Int?, sparkleLocales: String?, publicEdKey: String?, supportsDSA: Bool, appPath: URL, archivePath: URL) throws {
self.version = version
self._shortVersion = shortVersion
self.feedURL = feedURL
self.requiresSignedAppcast = requiresSignedAppcast
self.bundleIdentifier = bundleIdentifier
self.minimumSystemVersion = minimumSystemVersion ?? "12.0"
self.hardwareRequirements = hardwareRequirements
self.frameworkVersion = frameworkVersion
@@ -369,6 +371,7 @@ class ArchiveItem: CustomStringConvertible {
shortVersion: shortVersion,
feedURL: feedURL,
requiresSignedAppcast: requiresSignedAppcast,
bundleIdentifier: infoPlist[kCFBundleIdentifierKey as String] as? String,
minimumSystemVersion: minimumSystemVersion,
hardwareRequirements: hardwareRequirements,
frameworkVersion: frameworkVersion,
+14 -1
View File
@@ -311,7 +311,20 @@ func writeAppcast(appcastDestPath: URL, keys: PrivateKeys, disableEmbeddedSignWa
requiresSignedAppcast = requiresSignedAppcastFromArchives
}
if requiresSignedAppcast && keys.publicEdKey != nil && keys.privateEdKey != nil {
let existingBundleIdentifiers = Set(channel.elements(forName: SUAppcastElementBundleIdentifier).compactMap({ $0.stringValue?.trimmingCharacters(in: .whitespacesAndNewlines) }))
let archiveBundleIdentifiers = Set(appcast.versionsInFeed.compactMap({ appcast.archives[$0]?.bundleIdentifier }))
var bundleIdentifierIndex = try channel.nodes(forXPath: "item").first?.index ?? channel.childCount
for bundleIdentifier in archiveBundleIdentifiers.subtracting(existingBundleIdentifiers).sorted() {
let bundleIdentifierElement = XMLElement.element(withName: SUAppcastElementBundleIdentifier, uri: sparkleNS) as! XMLElement
bundleIdentifierElement.setChildren([text(bundleIdentifier)])
channel.insertChild(bundleIdentifierElement, at: bundleIdentifierIndex)
bundleIdentifierIndex += 1
}
}
// Keep track of already signed release note files so we avoid
// re-signing the same file in case the developer is using symlinks
// Path -> [(EdSignature, Length)]