NSLog Leakage

Cyberizm

Member
Joined
21 May 2026
Messages
22
Reaction score
56
Points
13
Vulnerable Code:

Code:
// Logging sensitive information with NSLog
NSString *myName = @"username";
NSString *myPass = @"password";
NSLog(@"Sending username %@ and password %@", myName, myPass);

Description: This vulnerable Objective-C code logs sensitive information (username and password) using NSLog. However, NSLog writes data to the Apple System Log (ASL), making this information retrievable by anyone with physical access to the device or with the ability to query the system log.

Patched Code:

Code:
// Disabling NSLog in non-debug builds
#ifdef DEBUG
# define NSLog(...) NSLog(__VA_ARGS__);
#else
# define NSLog(...)
#endif
Description: The patched Objective-C code disables NSLog in non-debug builds using a variadic macro. This prevents sensitive information from being logged in release builds, reducing the risk of exposing private data through the system log.

Swift:

Vulnerable Code:


Swift:
// Logging sensitive information with NSLog equivalent
let myName = "username"
let myPass = "password"
NSLog("Sending username \(myName) and password \(myPass)")
Description: This vulnerable Swift code logs sensitive information (username and password) using the equivalent of NSLog. However, similar to NSLog, this logs data to the system log, making it retrievable by anyone with physical access to the device or with the ability to query the system log.

Patched Code:

Code:
// Disabling NSLog equivalent in non-debug builds
#if DEBUG
func debugLog(_ message: String) {
NSLog(message)
}
#else
func debugLog(_ message: String) {
// No-op
}
#endif
Description: The patched Swift code defines a function debugLog that acts as a wrapper around NSLog. In non-debug builds, this function becomes a no-op, preventing sensitive information from being logged in release builds and reducing the risk of exposing private data through the system log.

Objective-C:

Vulnerable Code:


C++:
// Incorrectly managing cache, potentially leaking sensitive data
[[NSURLCache sharedURLCache] removeAllCachedResponses];
Description: The vulnerable Objective-C code attempts to remove all cached responses using removeAllCachedResponses method of the shared URL cache. However, this method only removes cache entries from memory, leaving the cached data on disk, potentially exposing sensitive information.

Patched Code:
C:
// Properly disabling caching to prevent data leakage
NSURLCache *urlCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:urlCache];
Description: The patched Objective-C code disables caching altogether by initializing a new NSURLCache instance with zero memory and disk capacities. This prevents data from being cached both in memory and on disk, reducing the risk of exposing sensitive information through cached data.

Swift:

Vulnerable Code:


// Attempting to prevent caching by setting cache policy
let request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 666.0)
Description: The vulnerable Swift code tries to prevent caching by setting the cache policy of a URLRequest to .reloadIgnoringLocalCacheData. However, this policy only prevents the URL loading system from retrieving cached responses, leaving previously cached data on disk, potentially exposing sensitive information.

Patched Code:

C:
// Properly disabling caching to prevent data leakage
URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
Description: The patched Swift code disables caching by assigning a new URLCache instance with zero memory and disk capacities to the shared URLCache. This ensures that no data is cached in memory or on disk, reducing the risk of exposing sensitive information through cached data.



Professional Hacking Services Available


We offer ethical security assessments and penetration testing for iOS and Android mobile devices. For inquiries:

- E-mail: cyberizm@proton.me / cyberizm@dnmx.cc


- Telegram: @cyb3rizm


- Signal: cyberizm.88





Contact us for discreet, professional assistance.