@@ -154,27 +154,34 @@ class Logic {
154
154
func addString( _ str: String ) { } // safe
155
155
}
156
156
157
+ // custom
158
+ class MyRemoteLogger {
159
+ func setPassword( password: String ) { }
160
+ func login( password: String ) { }
161
+ func logout( secret: String ) { }
162
+ }
163
+
157
164
// --- tests ---
158
165
159
166
func test1( password: String , passwordHash : String , passphrase: String , pass_phrase: String ) {
160
- print ( password) // $ hasCleartextLogging=160
161
- print ( password, separator: " " ) // $ $ hasCleartextLogging=161
162
- print ( " " , separator: password) // $ hasCleartextLogging=162
163
- print ( password, separator: " " , terminator: " " ) // $ hasCleartextLogging=163
164
- print ( " " , separator: password, terminator: " " ) // $ hasCleartextLogging=164
165
- print ( " " , separator: " " , terminator: password) // $ hasCleartextLogging=165
167
+ print ( password) // $ hasCleartextLogging=167
168
+ print ( password, separator: " " ) // $ $ hasCleartextLogging=168
169
+ print ( " " , separator: password) // $ hasCleartextLogging=169
170
+ print ( password, separator: " " , terminator: " " ) // $ hasCleartextLogging=170
171
+ print ( " " , separator: password, terminator: " " ) // $ hasCleartextLogging=171
172
+ print ( " " , separator: " " , terminator: password) // $ hasCleartextLogging=172
166
173
print ( passwordHash) // safe
167
174
168
- debugPrint ( password) // $ hasCleartextLogging=168
175
+ debugPrint ( password) // $ hasCleartextLogging=175
169
176
170
- dump ( password) // $ hasCleartextLogging=170
177
+ dump ( password) // $ hasCleartextLogging=177
171
178
172
- NSLog ( password) // $ hasCleartextLogging=172
173
- NSLog ( " %@ " , password) // $ hasCleartextLogging=173
174
- NSLog ( " %@ %@ " , " " , password) // $ hasCleartextLogging=174
175
- NSLog ( " \( password) " ) // $ hasCleartextLogging=175
176
- NSLogv ( " %@ " , getVaList ( [ password] ) ) // $ hasCleartextLogging=176
177
- NSLogv ( " %@ %@ " , getVaList ( [ " " , password] ) ) // $ hasCleartextLogging=177
179
+ NSLog ( password) // $ hasCleartextLogging=179
180
+ NSLog ( " %@ " , password) // $ hasCleartextLogging=180
181
+ NSLog ( " %@ %@ " , " " , password) // $ hasCleartextLogging=181
182
+ NSLog ( " \( password) " ) // $ hasCleartextLogging=182
183
+ NSLogv ( " %@ " , getVaList ( [ password] ) ) // $ hasCleartextLogging=183
184
+ NSLogv ( " %@ %@ " , getVaList ( [ " " , password] ) ) // $ hasCleartextLogging=184
178
185
NSLog ( passwordHash) // safe
179
186
NSLogv ( " %@ " , getVaList ( [ passwordHash] ) ) // safe
180
187
@@ -184,38 +191,38 @@ func test1(password: String, passwordHash : String, passphrase: String, pass_phr
184
191
log. log ( " \( password) " ) // safe
185
192
log. log ( " \( password, privacy: . auto) " ) // safe
186
193
log. log ( " \( password, privacy: . private) " ) // safe
187
- log. log ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=187
194
+ log. log ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=194
188
195
log. log ( " \( passwordHash, privacy: . public) " ) // safe
189
196
log. log ( " \( password, privacy: . sensitive) " ) // safe
190
- log. log ( " \( bankAccount) " ) // $ MISSING: hasCleartextLogging=190
191
- log. log ( " \( bankAccount, privacy: . auto) " ) // $ MISSING: hasCleartextLogging=191
197
+ log. log ( " \( bankAccount) " ) // $ MISSING: hasCleartextLogging=197
198
+ log. log ( " \( bankAccount, privacy: . auto) " ) // $ MISSING: hasCleartextLogging=198
192
199
log. log ( " \( bankAccount, privacy: . private) " ) // safe
193
- log. log ( " \( bankAccount, privacy: . public) " ) // $ MISSING: hasCleartextLogging=193
200
+ log. log ( " \( bankAccount, privacy: . public) " ) // $ MISSING: hasCleartextLogging=200
194
201
log. log ( " \( bankAccount, privacy: . sensitive) " ) // safe
195
- log. log ( level: . default, " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=195
196
- log. trace ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=196
202
+ log. log ( level: . default, " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=202
203
+ log. trace ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=203
197
204
log. trace ( " \( passwordHash, privacy: . public) " ) // safe
198
- log. debug ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=198
205
+ log. debug ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=205
199
206
log. debug ( " \( passwordHash, privacy: . public) " ) // safe
200
- log. info ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=200
207
+ log. info ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=207
201
208
log. info ( " \( passwordHash, privacy: . public) " ) // safe
202
- log. notice ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=202
209
+ log. notice ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=209
203
210
log. notice ( " \( passwordHash, privacy: . public) " ) // safe
204
- log. warning ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=204
211
+ log. warning ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=211
205
212
log. warning ( " \( passwordHash, privacy: . public) " ) // safe
206
- log. error ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=206
213
+ log. error ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=213
207
214
log. error ( " \( passwordHash, privacy: . public) " ) // safe
208
- log. critical ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=208
215
+ log. critical ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=215
209
216
log. critical ( " \( passwordHash, privacy: . public) " ) // safe
210
- log. fault ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=210
217
+ log. fault ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=217
211
218
log. fault ( " \( passwordHash, privacy: . public) " ) // safe
212
219
213
- NSLog ( passphrase) // $ hasCleartextLogging=213
214
- NSLog ( pass_phrase) // $ hasCleartextLogging=214
220
+ NSLog ( passphrase) // $ hasCleartextLogging=220
221
+ NSLog ( pass_phrase) // $ hasCleartextLogging=221
215
222
216
223
os_log ( " %@ " , log: . default, type: . default, " " ) // safe
217
- os_log ( " %@ " , log: . default, type: . default, password) // $ hasCleartextLogging=217
218
- os_log ( " %@ %@ %@ " , log: . default, type: . default, " " , " " , password) // $ hasCleartextLogging=218
224
+ os_log ( " %@ " , log: . default, type: . default, password) // $ hasCleartextLogging=224
225
+ os_log ( " %@ %@ %@ " , log: . default, type: . default, " " , " " , password) // $ hasCleartextLogging=225
219
226
}
220
227
221
228
class MyClass {
@@ -229,16 +236,16 @@ func doSomething(password: String) { }
229
236
func test3( x: String ) {
230
237
// alternative evidence of sensitivity...
231
238
232
- NSLog ( x) // $ MISSING: hasCleartextLogging=233
239
+ NSLog ( x) // $ MISSING: hasCleartextLogging=240
233
240
doSomething ( password: x) ;
234
- NSLog ( x) // $ hasCleartextLogging=233
241
+ NSLog ( x) // $ hasCleartextLogging=240
235
242
236
243
let y = getPassword ( ) ;
237
- NSLog ( y) // $ hasCleartextLogging=236
244
+ NSLog ( y) // $ hasCleartextLogging=243
238
245
239
246
let z = MyClass ( )
240
247
NSLog ( z. harmless) // safe
241
- NSLog ( z. password) // $ hasCleartextLogging=241
248
+ NSLog ( z. password) // $ hasCleartextLogging=248
242
249
}
243
250
244
251
struct MyOuter {
@@ -253,7 +260,7 @@ struct MyOuter {
253
260
func test3( mo : MyOuter ) {
254
261
// struct members...
255
262
256
- NSLog ( mo. password. value) // $ hasCleartextLogging=256
263
+ NSLog ( mo. password. value) // $ hasCleartextLogging=263
257
264
NSLog ( mo. harmless. value) // safe
258
265
}
259
266
@@ -277,39 +284,39 @@ func test4(harmless: String, password: String) {
277
284
print ( myString1) // safe
278
285
279
286
print ( password, to: & myString2)
280
- print ( myString2) // $ hasCleartextLogging=279
287
+ print ( myString2) // $ hasCleartextLogging=286
281
288
282
289
print ( " log: " + password, to: & myString3)
283
- print ( myString3) // $ hasCleartextLogging=282
290
+ print ( myString3) // $ hasCleartextLogging=289
284
291
285
292
debugPrint ( harmless, to: & myString4)
286
293
debugPrint ( myString4) // safe
287
294
288
295
debugPrint ( password, to: & myString5)
289
- debugPrint ( myString5) // $ hasCleartextLogging=288
296
+ debugPrint ( myString5) // $ hasCleartextLogging=295
290
297
291
298
dump ( harmless, to: & myString6)
292
299
dump ( myString6) // safe
293
300
294
301
dump ( password, to: & myString7)
295
- dump ( myString7) // $ hasCleartextLogging=294
302
+ dump ( myString7) // $ hasCleartextLogging=301
296
303
297
304
myString8. write ( harmless)
298
305
print ( myString8)
299
306
300
307
myString9. write ( password)
301
- print ( myString9) // $ hasCleartextLogging=300
308
+ print ( myString9) // $ hasCleartextLogging=307
302
309
303
310
myString10. write ( harmless)
304
311
myString10. write ( password)
305
312
myString10. write ( harmless)
306
- print ( myString10) // $ hasCleartextLogging=304
313
+ print ( myString10) // $ hasCleartextLogging=311
307
314
308
315
harmless. write ( to: & myString11)
309
316
print ( myString11)
310
317
311
318
password. write ( to: & myString12)
312
- print ( myString12) // $ hasCleartextLogging=311
319
+ print ( myString12) // $ hasCleartextLogging=318
313
320
314
321
print ( password, to: & myString13) // $ safe - only printed to another string
315
322
debugPrint ( password, to: & myString13) // $ safe - only printed to another string
@@ -324,61 +331,66 @@ func test5(password: String, caseNum: Int) {
324
331
325
332
switch caseNum {
326
333
case 0 :
327
- assert ( false , password) // $ hasCleartextLogging=327
334
+ assert ( false , password) // $ hasCleartextLogging=334
328
335
case 1 :
329
- assertionFailure ( password) // $ hasCleartextLogging=329
336
+ assertionFailure ( password) // $ hasCleartextLogging=336
330
337
case 2 :
331
- precondition ( false , password) // $ hasCleartextLogging=331
338
+ precondition ( false , password) // $ hasCleartextLogging=338
332
339
case 3 :
333
- preconditionFailure ( password) // $ hasCleartextLogging=333
340
+ preconditionFailure ( password) // $ hasCleartextLogging=340
334
341
default :
335
- fatalError ( password) // $ hasCleartextLogging=335
342
+ fatalError ( password) // $ hasCleartextLogging=342
336
343
}
337
344
}
338
345
339
346
func test6( passwordString: String ) {
340
- let e = NSException ( name: NSExceptionName ( " exception " ) , reason: " \( passwordString) is incorrect! " , userInfo: nil ) // $ hasCleartextLogging=340
347
+ let e = NSException ( name: NSExceptionName ( " exception " ) , reason: " \( passwordString) is incorrect! " , userInfo: nil ) // $ hasCleartextLogging=347
341
348
e. raise ( )
342
349
343
- NSException . raise ( NSExceptionName ( " exception " ) , format: " \( passwordString) is incorrect! " , arguments: getVaList ( [ ] ) ) // $ hasCleartextLogging=343
344
- NSException . raise ( NSExceptionName ( " exception " ) , format: " %s is incorrect! " , arguments: getVaList ( [ passwordString] ) ) // $ hasCleartextLogging=344
350
+ NSException . raise ( NSExceptionName ( " exception " ) , format: " \( passwordString) is incorrect! " , arguments: getVaList ( [ ] ) ) // $ hasCleartextLogging=350
351
+ NSException . raise ( NSExceptionName ( " exception " ) , format: " %s is incorrect! " , arguments: getVaList ( [ passwordString] ) ) // $ hasCleartextLogging=351
345
352
346
- _ = dprintf ( 0 , " \( passwordString) is incorrect! " ) // $ hasCleartextLogging=346
347
- _ = dprintf ( 0 , " %s is incorrect! " , passwordString) // $ hasCleartextLogging=347
348
- _ = dprintf ( 0 , " %s: %s is incorrect! " , " foo " , passwordString) // $ hasCleartextLogging=348
349
- _ = vprintf ( " \( passwordString) is incorrect! " , getVaList ( [ ] ) ) // $ hasCleartextLogging=349
350
- _ = vprintf ( " %s is incorrect! " , getVaList ( [ passwordString] ) ) // $ hasCleartextLogging=350
351
- _ = vfprintf ( nil , " \( passwordString) is incorrect! " , getVaList ( [ ] ) ) // $ hasCleartextLogging=351
352
- _ = vfprintf ( nil , " %s is incorrect! " , getVaList ( [ passwordString] ) ) // $ hasCleartextLogging=352
353
+ _ = dprintf ( 0 , " \( passwordString) is incorrect! " ) // $ hasCleartextLogging=353
354
+ _ = dprintf ( 0 , " %s is incorrect! " , passwordString) // $ hasCleartextLogging=354
355
+ _ = dprintf ( 0 , " %s: %s is incorrect! " , " foo " , passwordString) // $ hasCleartextLogging=355
356
+ _ = vprintf ( " \( passwordString) is incorrect! " , getVaList ( [ ] ) ) // $ hasCleartextLogging=356
357
+ _ = vprintf ( " %s is incorrect! " , getVaList ( [ passwordString] ) ) // $ hasCleartextLogging=357
358
+ _ = vfprintf ( nil , " \( passwordString) is incorrect! " , getVaList ( [ ] ) ) // $ hasCleartextLogging=358
359
+ _ = vfprintf ( nil , " %s is incorrect! " , getVaList ( [ passwordString] ) ) // $ hasCleartextLogging=359
353
360
_ = vasprintf_l ( nil , nil , " \( passwordString) is incorrect! " , getVaList ( [ ] ) ) // good (`sprintf` is not logging)
354
361
_ = vasprintf_l ( nil , nil , " %s is incorrect! " , getVaList ( [ passwordString] ) ) // good (`sprintf` is not logging)
355
362
}
356
363
357
- func test7( authKey: String , authKey2: Int , authKey3: Float ) {
358
- log ( message: authKey) // $ hasCleartextLogging=358
359
- log ( message: String ( authKey2) ) // $ hasCleartextLogging=359
360
- logging ( message: authKey) // $ hasCleartextLogging=360
361
- logfile ( file: 0 , message: authKey) // $ hasCleartextLogging=361
362
- logMessage ( NSString ( string: authKey) ) // $ hasCleartextLogging=362
363
- logInfo ( authKey) // $ MISSING: hasCleartextLogging=363
364
- logError ( errorMsg: authKey) // $ hasCleartextLogging=364
364
+ func test7( authKey: String , authKey2: Int , authKey3: Float , password : String , secret : String ) {
365
+ log ( message: authKey) // $ hasCleartextLogging=365
366
+ log ( message: String ( authKey2) ) // $ hasCleartextLogging=366
367
+ logging ( message: authKey) // $ hasCleartextLogging=367
368
+ logfile ( file: 0 , message: authKey) // $ hasCleartextLogging=368
369
+ logMessage ( NSString ( string: authKey) ) // $ hasCleartextLogging=369
370
+ logInfo ( authKey) // $ MISSING: hasCleartextLogging=370
371
+ logError ( errorMsg: authKey) // $ hasCleartextLogging=371
365
372
harmless ( authKey) // GOOD: not logging
366
373
_ = logarithm ( authKey3) // GOOD: not logging
367
374
doLogin ( login: authKey) // GOOD: not logging
368
375
369
376
let logger = LogFile ( )
370
377
let msg = " authKey: " + authKey
371
- logger. log ( msg) // $ hasCleartextLogging=370
372
- logger. trace ( msg) // $ hasCleartextLogging=370
373
- logger. debug ( msg) // $ hasCleartextLogging=370
374
- logger. info ( NSString ( string: msg) ) // $ hasCleartextLogging=370
375
- logger. notice ( msg) // $ hasCleartextLogging=370
376
- logger. warning ( msg) // $ hasCleartextLogging=370
377
- logger. error ( msg) // $ hasCleartextLogging=370
378
- logger. critical ( msg) // $ hasCleartextLogging=370
379
- logger. fatal ( msg) // $ hasCleartextLogging=370
378
+ logger. log ( msg) // $ hasCleartextLogging=377
379
+ logger. trace ( msg) // $ hasCleartextLogging=377
380
+ logger. debug ( msg) // $ hasCleartextLogging=377
381
+ logger. info ( NSString ( string: msg) ) // $ hasCleartextLogging=377
382
+ logger. notice ( msg) // $ hasCleartextLogging=377
383
+ logger. warning ( msg) // $ hasCleartextLogging=377
384
+ logger. error ( msg) // $ hasCleartextLogging=377
385
+ logger. critical ( msg) // $ hasCleartextLogging=377
386
+ logger. fatal ( msg) // $ hasCleartextLogging=377
380
387
381
388
let logic = Logic ( )
382
389
logic. addInt ( authKey2) // GOOD: not logging
383
- logic. addString ( authKey) // $ SPURIOUS: hasCleartextLogging=383 (not logging)
390
+ logic. addString ( authKey) // $ SPURIOUS: hasCleartextLogging=390 (not logging)
391
+
392
+ let rlogger = MyRemoteLogger ( )
393
+ rlogger. setPassword ( password: password) // $ SPURIOUS: hasCleartextLogging=393 (not logging)
394
+ rlogger. login ( password: password) // $ SPURIOUS: hasCleartextLogging=394 (not logging)
395
+ rlogger. logout ( secret: secret) // $ SPURIOUS: hasCleartextLogging=395 (not logging)
384
396
}
0 commit comments