@@ -4,11 +4,41 @@ import OpenIAP
44enum FlutterIapHelper {
55 // MARK: - Sanitization
66
7+ private static let identifierKeys : Set < String > = [
8+ " id " ,
9+ " transactionId " ,
10+ " productId " ,
11+ " offerId " ,
12+ " originalTransactionIdentifierIOS " ,
13+ " subscriptionGroupIdIOS " ,
14+ " webOrderLineItemIdIOS " ,
15+ " orderIdAndroid " ,
16+ " obfuscatedAccountIdAndroid " ,
17+ " obfuscatedProfileIdAndroid "
18+ ]
19+
20+ private static let sensitiveKeyFragments : [ String ] = [
21+ " token " ,
22+ " receipt " ,
23+ " jws " ,
24+ " signature "
25+ ]
26+
727 static func sanitizeDictionary( _ dictionary: [ String : Any ? ] ) -> [ String : Any ] {
828 var result : [ String : Any ] = [ : ]
929 for (key, value) in dictionary {
10- if let value {
11- result [ key] = value
30+ let lowerKey = key. lowercased ( )
31+ if sensitiveKeyFragments. contains ( where: { lowerKey. contains ( $0) } ) {
32+ result [ key] = " hidden "
33+ continue
34+ }
35+
36+ guard let sanitizedValue = sanitizeValue ( value) else { continue }
37+
38+ if let number = sanitizedValue as? NSNumber , identifierKeys. contains ( key) {
39+ result [ key] = number. stringValue
40+ } else {
41+ result [ key] = sanitizedValue
1242 }
1343 }
1444 return result
@@ -21,27 +51,23 @@ enum FlutterIapHelper {
2151 static func sanitizeValue( _ value: Any ? ) -> Any ? {
2252 guard let value else { return nil }
2353
24- if let dictionary = value as? [ String : Any ] {
25- return dictionary. reduce ( into: [ String: Any] ( ) ) { result, element in
26- let ( key, rawValue) = element
27- if key. lowercased ( ) . contains ( " token " ) {
28- result [ key] = " hidden "
29- } else if let sanitized = sanitizeValue ( rawValue) {
30- result [ key] = sanitized
31- }
32- }
54+ if let dictionary = value as? [ String : Any ? ] {
55+ return sanitizeDictionary ( dictionary)
3356 }
3457
35- if let optionalDictionary = value as? [ String : Any ? ] {
58+ if let dictionary = value as? [ String : Any ] {
59+ let optionalDictionary = dictionary. reduce ( into: [ String: Any? ] ( ) ) { result, element in
60+ result [ element. key] = element. value
61+ }
3662 return sanitizeDictionary ( optionalDictionary)
3763 }
3864
39- if let array = value as? [ Any ] {
65+ if let array = value as? [ Any ? ] {
4066 return array. compactMap { sanitizeValue ( $0) }
4167 }
4268
43- if let optionalArray = value as? [ Any ? ] {
44- return optionalArray . compactMap { sanitizeValue ( $0) }
69+ if let array = value as? [ Any ] {
70+ return array . compactMap { sanitizeValue ( $0) }
4571 }
4672
4773 return value
0 commit comments