Skip to content

Commit

Permalink
comply with secure restorable state (required when compiling on macOS…
Browse files Browse the repository at this point in the history
… 14)
  • Loading branch information
gobbledegook committed Nov 16, 2023
1 parent c4e9740 commit fc82688
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CreeveyController.m
Expand Up @@ -985,6 +985,10 @@ - (void)showExifThumbnail:(BOOL)b shrinkWindow:(BOOL)shrink {


#pragma mark new window stuff
- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app {
// opt in to secure behavior in macOS 12 and later. See the AppKit release notes for macOS 14.
return YES;
}
+ (void)restoreWindowWithIdentifier:(NSString *)identifier
state:(NSCoder *)state
completionHandler:(void (^)(NSWindow *, NSError *))completionHandler
Expand Down
4 changes: 3 additions & 1 deletion CreeveyMainWindowController.m
Expand Up @@ -99,7 +99,9 @@ - (void)window:(NSWindow *)window willEncodeRestorableState:(NSCoder *)state

- (void)window:(NSWindow *)window didDecodeRestorableState:(NSCoder *)state
{
NSDictionary *data = [state decodeObjectForKey:@"creeveyWindowState"];
// as of macOS 12, apps must support secure restorable state (apparently malicious attacks could happen if there was bad data masquerading as your saved state)
// the fix is apparently to give a list of secure classes when you ask to decode the data. See the AppKit release notes for macOS 12.
NSDictionary *data = [state decodeObjectOfClasses:[NSSet setWithArray:@[[NSDictionary class],[NSString class],[NSNumber class]]] forKey:@"creeveyWindowState"];
if (![data isKindOfClass:[NSDictionary class]]) data = @{};
NSString *path = data[@"path"];
if (![path isKindOfClass:[NSString class]]) path = nil;
Expand Down

0 comments on commit fc82688

Please sign in to comment.