Sensitive information logged in plaintext in Swift

Sensitive information logged in plaintext in Swift

Description

Logging passwords, tokens, session IDs or API keys with print, NSLog, os_log or Logger can expose them to anyone who can read device logs, crash reports or operational logs.

Potential impact

  • Theft of authentication tokens or sessions.
  • Exposure of personal information and internal API keys.
  • Spread of sensitive information through log collection systems.

Remediation

Log the event name. If you need to trace it, use a separate tracking ID. Remove sensitive fields in a shared logging filter or helper, or replace their values with a fixed placeholder.

Examples

Before

swift
func logToken(token: String) {
    NSLog("token %@", token)
}

After

swift
func logToken() {
    NSLog("token refreshed")
}

logToken() takes no token argument and logs only token refreshed.

References