Skip to content

Commit ac5a19d

Browse files
authored
Merge pull request #21 from nativeapptemplate/secure-console-logs
Prevent sensitive data from leaking to iOS console in Release builds
2 parents 501cf9c + 9c29fc6 commit ac5a19d

6 files changed

Lines changed: 27 additions & 7 deletions

File tree

NativeAppTemplate/Logging/Logger.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
// NativeAppTemplate
44
//
55

6+
import os
7+
8+
private let appLogger = os.Logger(subsystem: "com.nativeapptemplate", category: "app")
9+
610
struct Failure {
711
static func signUp(from source: (some Any).Type, reason: String) -> Self {
812
.init(source: source, action: "signUp", reason: reason)
@@ -63,12 +67,12 @@ struct Failure {
6367
private let reason: String
6468

6569
func log() {
66-
print(
67-
[
68-
"source": source,
69-
"action": action,
70-
"reason": reason
71-
]
70+
appLogger.error(
71+
"""
72+
\(self.action, privacy: .public) \
73+
source=\(self.source, privacy: .public) \
74+
reason=\(self.reason, privacy: .private)
75+
"""
7276
)
7377
}
7478
}
@@ -95,6 +99,6 @@ struct Event {
9599
private let action: String
96100

97101
func log() {
98-
print("EVENT:: \(["source": source, "action": action])")
102+
appLogger.info("EVENT:: source: \(self.source, privacy: .public), action: \(self.action, privacy: .public)")
99103
}
100104
}

NativeAppTemplate/Login/LoginRepository.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import Foundation
1818
let loggedInShopkeeper = try keychainStore.retrieve()
1919
_currentShopkeeper = Shopkeeper(from: loggedInShopkeeper)
2020
} catch {
21+
#if DEBUG
2122
print(error)
23+
#endif
2224
}
2325
}
2426
return _currentShopkeeper
@@ -86,7 +88,9 @@ import Foundation
8688
do {
8789
try keychainStore.remove()
8890
} catch {
91+
#if DEBUG
8992
print(error)
93+
#endif
9094
}
9195
}
9296
}

NativeAppTemplate/Login/SignUpRepository.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ import Foundation
100100
do {
101101
try keychainStore.remove()
102102
} catch {
103+
#if DEBUG
103104
print(error)
105+
#endif
104106
}
105107
}
106108
}

NativeAppTemplate/NFCManager.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ extension NFCManager: NFCNDEFReaderSessionDelegate {
205205
isLock: isLock
206206
) { error in
207207
guard error == nil else { return }
208+
#if DEBUG
208209
print(">>> Write: \(userNdefMessage)")
210+
#endif
209211
}
210212
}
211213

@@ -263,6 +265,8 @@ extension NFCManager: NFCNDEFReaderSessionDelegate {
263265
func readerSessionDidBecomeActive(_ session: NFCNDEFReaderSession) {}
264266

265267
func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
268+
#if DEBUG
266269
print("readerSession error: \(error.localizedDescription)")
270+
#endif
267271
}
268272
}

NativeAppTemplate/Persistence/KeychainStore/KeychainStore.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ extension KeychainStore {
6060

6161
func store(_ data: DataType) throws {
6262
let archived: Data
63+
#if DEBUG
6364
print("data: \(data)")
65+
#endif
6466
do {
6567
archived = try NSKeyedArchiver.archivedData(withRootObject: data, requiringSecureCoding: true)
6668
} catch {

NativeAppTemplate/Utilities/Utility.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,16 @@ enum Utility {
7575
if let itemTagId = item.value {
7676
itemTagInfo.id = itemTagId
7777
}
78+
#if DEBUG
7879
print("item_tag_id: \(String(describing: itemTagInfo.id))")
80+
#endif
7981
case "type":
8082
if let type = item.value {
8183
itemTagInfo.type = type
8284
}
85+
#if DEBUG
8386
print("type: \(String(describing: itemTagInfo.type))")
87+
#endif
8488
default:
8589
break
8690
}

0 commit comments

Comments
 (0)