mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-27 05:04:27 +00:00
Rewrite ATS check by distinguishing if Sparkle is in XPC service or not
If it's not in a XPC service, then the main bundle decides the rules.
This commit is contained in:
1 parent
2a89393853
commit
3b892524a6
4 files changed
+61
-9
No files matched your search
@@ -7,6 +7,6 @@ case "${SPARKLE_ALLOW_ARBITRARY_HTTP_LOADS}" in
|
||||
/usr/libexec/PlistBuddy -c "Set :NSAppTransportSecurity:NSAllowsArbitraryLoads YES" "${INFOPLIST}"
|
||||
;;
|
||||
"NO"|"0")
|
||||
/usr/libexec/PlistBuddy -c "Set :NSAppTransportSecurity:NSAllowsArbitraryLoads NO" "${INFOPLIST}"
|
||||
/usr/libexec/PlistBuddy -c "Delete :NSAppTransportSecurity" "${INFOPLIST}"
|
||||
;;
|
||||
esac
|
||||
Vendored
+50
-5
@@ -25,6 +25,7 @@
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUInstallationInfo.h"
|
||||
#import "SUErrors.h"
|
||||
#import "SUXPCServiceInfo.h"
|
||||
|
||||
#ifdef _APPKITDEFINES_H
|
||||
#error This is a "core" class and should NOT import AppKit
|
||||
@@ -118,6 +119,27 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)checkATSIssueForBundleURL:(NSURL *)bundleURL getBundleExists:(BOOL *)bundleExists
|
||||
{
|
||||
if (bundleURL == nil) {
|
||||
if (bundleExists != NULL) {
|
||||
*bundleExists = NO;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSBundle *bundle = [NSBundle bundleWithURL:bundleURL];
|
||||
if (bundleExists != NULL) {
|
||||
*bundleExists = (bundle != nil);
|
||||
}
|
||||
|
||||
if (bundle == nil) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
return ([bundle objectForInfoDictionaryKey:@"NSAppTransportSecurity"] == nil);
|
||||
}
|
||||
|
||||
- (BOOL)checkIfConfiguredProperly:(NSError * __autoreleasing *)error
|
||||
{
|
||||
if (self.sparkleBundle == nil) {
|
||||
@@ -155,12 +177,35 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
|
||||
}
|
||||
|
||||
BOOL servingOverHttps = [[[feedURL scheme] lowercaseString] isEqualToString:@"https"];
|
||||
BOOL allowsArbitraryHTTPLoads = SPARKLE_ALLOW_ARBITRARY_HTTP_LOADS;
|
||||
if (!allowsArbitraryHTTPLoads && !servingOverHttps) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsecureFeedURLError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"You must change the feed URL (%@) to use HTTPS or use a build of Sparkle with App Transport Security disabled.\n\nFor more information:\nhttps://sparkle-project.org/documentation/app-transport-security/", [feedURL absoluteString]] }];
|
||||
if (!servingOverHttps) {
|
||||
BOOL foundXPCAppcastDownloaderService = NO;
|
||||
BOOL foundATSAppcastIssue = [self checkATSIssueForBundleURL:SUXPCServiceURL(@APPCAST_DOWNLOADER_PRODUCT_NAME) getBundleExists:&foundXPCAppcastDownloaderService];
|
||||
|
||||
BOOL foundXPCUpdateDownloaderService = NO;
|
||||
BOOL foundATSUpdateIssue = NO;
|
||||
if (!foundATSAppcastIssue) {
|
||||
foundATSUpdateIssue = [self checkATSIssueForBundleURL:SUXPCServiceURL(@UPDATE_DOWNLOADER_PRODUCT_NAME) getBundleExists:&foundXPCUpdateDownloaderService];
|
||||
}
|
||||
|
||||
NSBundle *mainBundle = [NSBundle mainBundle];
|
||||
BOOL foundATSMainBundleIssue = NO;
|
||||
if (!foundATSAppcastIssue && !foundATSUpdateIssue && (!foundXPCAppcastDownloaderService || !foundXPCUpdateDownloaderService)) {
|
||||
BOOL foundATSIssue = ([mainBundle objectForInfoDictionaryKey:@"NSAppTransportSecurity"] == nil);
|
||||
BOOL updatingMainBundle = [self.host.bundle isEqualTo:mainBundle];
|
||||
|
||||
if (updatingMainBundle) {
|
||||
// The only way we'll know for sure if there is an issue is if the main bundle is the same as the one we're updating
|
||||
// We don't want to generate false positives..
|
||||
foundATSMainBundleIssue = foundATSIssue;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundATSAppcastIssue || foundATSUpdateIssue || foundATSMainBundleIssue) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsecureFeedURLError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"You must change the feed URL (%@) to use HTTPS or use a build of Sparkle with App Transport Security disabled.\n\nFor more information:\nhttps://sparkle-project.org/documentation/app-transport-security/", [feedURL absoluteString]] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
|
||||
Vendored
+2
@@ -12,4 +12,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
BOOL SUXPCServiceExists(NSString *bundleName);
|
||||
|
||||
NSURL * _Nullable SUXPCServiceURL(NSString *bundleName);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
Vendored
+8
-3
@@ -9,15 +9,20 @@
|
||||
#import "SUXPCServiceInfo.h"
|
||||
|
||||
BOOL SUXPCServiceExists(NSString *bundleName)
|
||||
{
|
||||
NSURL *xpcBundleURL = SUXPCServiceURL(bundleName);
|
||||
return (xpcBundleURL != nil && [xpcBundleURL checkResourceIsReachableAndReturnError:NULL]);
|
||||
}
|
||||
|
||||
NSURL * _Nullable SUXPCServiceURL(NSString *bundleName)
|
||||
{
|
||||
NSBundle *mainBundle = [NSBundle mainBundle];
|
||||
NSURL *executableURL = mainBundle.executableURL;
|
||||
if (executableURL == nil) {
|
||||
return NO;
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSURL *xpcBundleURL = [[[executableURL.URLByDeletingLastPathComponent.URLByDeletingLastPathComponent URLByAppendingPathComponent:@"XPCServices"] URLByAppendingPathComponent:bundleName] URLByAppendingPathExtension:@"xpc"];
|
||||
|
||||
BOOL serviceExists = [xpcBundleURL checkResourceIsReachableAndReturnError:NULL];
|
||||
return serviceExists;
|
||||
return xpcBundleURL;
|
||||
}
|
||||
Reference in new issue
Block a user