Cocoanetics / DTCoreText

Methods to allow using HTML code with CoreText
BSD 2-Clause "Simplified" License
6.34k stars 1.18k forks source link

Switch to Secure Object Archiving APIs #1259

Open guraghav opened 2 years ago

guraghav commented 2 years ago

Hello,

Created this issue to address the vulnerability with using NSCoding. The NSCoding does not verify the type of object upon deserialization and therefore is vulnerable to object substitution attacks.

To mitigate this vulnerability, Apple introduced the NSSecureCoding protocol along with the following secure methods of NSKeyedArchiver and NSKeyedUnarchiver, which are robust against this type of attack:

// Secure NSKeyedUnarchiver methods
- (instancetype)initForReadingFromData:(NSData *)data error:(NSError **)error;
+ (id)unarchivedObjectOfClass:(Class)cls fromData:(NSData *)data error:(NSError **)error;
+ (id)unarchivedObjectOfClasses:(NSSet<Class> *)classes fromData:(NSData *)data error:(NSError **)error;

// Secure NSKeyedArchiver methods
- (instancetype)initRequiringSecureCoding:(BOOL)requiresSecureCoding;
+ (NSData *)archivedDataWithRootObject:(id)object requiringSecureCoding:(BOOL)requiresSecureCoding error:(NSError **)error;

Apple provides more information in the WWDC20 session, 'Securing Your App'.

The places where unsecure NSKeyedArchiver and NSKeyedUnarchiver is called :