Skip to content

Commit f1a4e57

Browse files
fix(ios-sdk): redact filesystem paths in log output (#408)
* fix(ios-sdk): replace full filesystem paths with lastPathComponent in logs to prevent PII leakage * fix(ios-sdk): redact path in error message and migrate to URL(filePath:) Swift 6 API * fix(ios-sdk): consolidate URL(filePath:) into single modelURL constant in DiffusionPlatformService
1 parent db4c6d7 commit f1a4e57

5 files changed

Lines changed: 27 additions & 25 deletions

File tree

sdk/runanywhere-swift/Sources/RunAnywhere/Features/Diffusion/DiffusionPlatformService.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,18 @@ public actor DiffusionPlatformService {
5454
disableSafetyChecker: Bool = false,
5555
tokenizerSource: DiffusionTokenizerSource = .sd15
5656
) async throws {
57-
logger.info("Initializing diffusion pipeline from: \(modelPath)")
57+
let modelURL = URL(filePath: modelPath)
58+
logger.info("Initializing diffusion pipeline from: \(modelURL.lastPathComponent)")
5859
logger.info("Tokenizer source: \(tokenizerSource.description)")
5960

6061
// Verify the directory exists
6162
guard FileManager.default.fileExists(atPath: modelPath) else {
62-
throw SDKError.diffusion(.modelNotFound, "Model directory not found: \(modelPath)")
63+
throw SDKError.diffusion(.modelNotFound, "Model directory not found: \(modelURL.lastPathComponent)")
6364
}
6465

6566
// Find the actual model directory (handles nested directory structure from zip extraction)
66-
let resourceURL = try findModelResourceDirectory(at: URL(fileURLWithPath: modelPath))
67-
logger.info("Using model resources from: \(resourceURL.path)")
67+
let resourceURL = try findModelResourceDirectory(at: modelURL)
68+
logger.info("Using model resources from: \(resourceURL.lastPathComponent)")
6869

6970
// Ensure tokenizer files exist (Apple's compiled models don't include them)
7071
try await ensureTokenizerFiles(at: resourceURL, source: tokenizerSource)
@@ -135,7 +136,7 @@ public actor DiffusionPlatformService {
135136
}
136137

137138
// If we get here, we couldn't find the model files - return base URL and let the pipeline report the error
138-
logger.warning("Could not find Unet.mlmodelc in \(baseURL.path) or its subdirectories")
139+
logger.warning("Could not find Unet.mlmodelc in \(baseURL.lastPathComponent) or its subdirectories")
139140
return baseURL
140141
}
141142

sdk/runanywhere-swift/Sources/RunAnywhere/Foundation/Bridge/Extensions/CppBridge+ModelPaths.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension CppBridge {
3232
throw SDKError.general(.initializationFailed, "Failed to set base directory")
3333
}
3434

35-
logger.debug("Base directory set to: \(baseDir.path)")
35+
logger.debug("Base directory set to: \(baseDir.lastPathComponent)")
3636
}
3737

3838
/// Get the configured base directory

sdk/runanywhere-swift/Sources/RunAnywhere/Infrastructure/Download/Utilities/ArchiveUtility.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public final class ArchiveUtility {
293293
progressHandler?(0.4 + progress * 0.6)
294294
})
295295

296-
logger.info("tar.xz extraction completed to: \(destinationURL.path)")
296+
logger.info("tar.xz extraction completed to: \(destinationURL.lastPathComponent)")
297297
progressHandler?(1.0)
298298
}
299299

@@ -338,7 +338,7 @@ public final class ArchiveUtility {
338338
pathEncoding: .utf8
339339
)
340340

341-
logger.info("zip extraction completed to: \(destinationURL.path)")
341+
logger.info("zip extraction completed to: \(destinationURL.lastPathComponent)")
342342
progressHandler?(1.0)
343343
} catch {
344344
logger.error("Zip extraction failed: \(error)")
@@ -440,7 +440,7 @@ public final class ArchiveUtility {
440440
compressionMethod: .deflate,
441441
progress: nil
442442
)
443-
logger.info("Created zip archive at: \(destinationURL.path)")
443+
logger.info("Created zip archive at: \(destinationURL.lastPathComponent)")
444444
} catch {
445445
logger.error("Failed to create zip archive: \(error)")
446446
throw SDKError.download(.extractionFailed, "Failed to create archive: \(error.localizedDescription)", underlying: error)

sdk/runanywhere-swift/Sources/RunAnywhere/Public/Extensions/Diffusion/RunAnywhere+Diffusion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public extension RunAnywhere {
185185
try await ensureServicesReady()
186186

187187
SDKLogger.shared.info("[Diffusion] Loading model '\(modelId)' via C++ component layer")
188-
SDKLogger.shared.info("[Diffusion] Model path: \(modelPath)")
188+
SDKLogger.shared.info("[Diffusion] Model path: \(URL(filePath: modelPath).lastPathComponent)")
189189

190190
// Configure the component if configuration is provided
191191
if let config = configuration {

sdk/runanywhere-swift/Sources/RunAnywhere/Public/Extensions/Models/RunAnywhere+ModelManagement.swift

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ extension RunAnywhere {
3535

3636
// Log model info for debugging
3737
let logger = SDKLogger(category: "ModelManagement")
38-
logger.info("Loading model: id=\(modelId), framework=\(modelInfo.framework), format=\(modelInfo.format), localPath=\(modelInfo.localPath?.path ?? "nil")")
38+
let localName = modelInfo.localPath?.lastPathComponent ?? "nil"
39+
logger.info("Loading model: id=\(modelId), framework=\(modelInfo.framework), format=\(modelInfo.format), localPath=\(localName)")
3940

4041
// Resolve actual model file path
4142
let modelPath = try resolveModelFilePath(for: modelInfo)
42-
logger.info("Resolved model path: \(modelPath.path)")
43+
logger.info("Resolved model path: \(modelPath.lastPathComponent)")
4344
try await CppBridge.LLM.shared.loadModel(modelPath.path, modelId: modelId, modelName: modelInfo.name)
4445
}
4546

@@ -67,22 +68,22 @@ extension RunAnywhere {
6768

6869
// Check if there's a nested folder with the model name (from archive extraction)
6970
let nestedFolder = modelFolder.appendingPathComponent(modelId)
70-
logger.debug("Checking nested folder: \(nestedFolder.path)")
71+
logger.debug("Checking nested folder: \(nestedFolder.lastPathComponent)")
7172

7273
if FileManager.default.fileExists(atPath: nestedFolder.path) {
7374
var isDir: ObjCBool = false
7475
if FileManager.default.fileExists(atPath: nestedFolder.path, isDirectory: &isDir), isDir.boolValue {
7576
// Check if this nested folder contains model files
7677
if hasONNXModelFiles(at: nestedFolder) {
77-
logger.info("Found ONNX model at nested path: \(nestedFolder.path)")
78+
logger.info("Found ONNX model at nested path: \(nestedFolder.lastPathComponent)")
7879
return nestedFolder
7980
}
8081
}
8182
}
8283

8384
// Check if model files exist directly in the model folder
8485
if hasONNXModelFiles(at: modelFolder) {
85-
logger.info("Found ONNX model at folder: \(modelFolder.path)")
86+
logger.info("Found ONNX model at folder: \(modelFolder.lastPathComponent)")
8687
return modelFolder
8788
}
8889

@@ -93,15 +94,15 @@ extension RunAnywhere {
9394
var isDir: ObjCBool = false
9495
if FileManager.default.fileExists(atPath: item.path, isDirectory: &isDir), isDir.boolValue {
9596
if hasONNXModelFiles(at: item) {
96-
logger.info("Found ONNX model in subdirectory: \(item.path)")
97+
logger.info("Found ONNX model in subdirectory: \(item.lastPathComponent)")
9798
return item
9899
}
99100
}
100101
}
101102
}
102103

103104
// Fallback to model folder
104-
logger.warning("No ONNX model files found, falling back to: \(modelFolder.path)")
105+
logger.warning("No ONNX model files found, falling back to: \(modelFolder.lastPathComponent)")
105106
return modelFolder
106107
}
107108

@@ -138,37 +139,37 @@ extension RunAnywhere {
138139
format: model.format
139140
)
140141

141-
logger.debug("Expected model path: \(expectedPath.path)")
142+
logger.debug("Expected model path: \(expectedPath.lastPathComponent)")
142143

143144
// If expected path exists, use it
144145
if FileManager.default.fileExists(atPath: expectedPath.path) {
145-
logger.info("Found model at expected path: \(expectedPath.path)")
146+
logger.info("Found model at expected path: \(expectedPath.lastPathComponent)")
146147
return expectedPath
147148
}
148149

149150
// Find files with the expected extension in model folder
150151
let expectedExtension = model.format.rawValue.lowercased()
151152
if let modelFile = findModelFile(in: modelFolder, extensions: [expectedExtension, "gguf", "bin"]) {
152-
logger.info("Found model file: \(modelFile.path)")
153+
logger.info("Found model file: \(modelFile.lastPathComponent)")
153154
return modelFile
154155
}
155156

156157
// Search in nested subdirectories (archives often create nested folders)
157-
logger.debug("Searching nested directories in: \(modelFolder.path)")
158+
logger.debug("Searching nested directories in: \(modelFolder.lastPathComponent)")
158159
if let contents = try? FileManager.default.contentsOfDirectory(at: modelFolder, includingPropertiesForKeys: [.isDirectoryKey]) {
159160
for item in contents {
160161
var isDir: ObjCBool = false
161162
if FileManager.default.fileExists(atPath: item.path, isDirectory: &isDir), isDir.boolValue {
162163
if let modelFile = findModelFile(in: item, extensions: [expectedExtension, "gguf", "bin"]) {
163-
logger.info("Found model file in nested directory: \(modelFile.path)")
164+
logger.info("Found model file in nested directory: \(modelFile.lastPathComponent)")
164165
return modelFile
165166
}
166167
}
167168
}
168169
}
169170

170171
// Fallback to expected path
171-
logger.warning("Model file not found, falling back to: \(expectedPath.path)")
172+
logger.warning("Model file not found, falling back to: \(expectedPath.lastPathComponent)")
172173
return expectedPath
173174
}
174175

@@ -243,7 +244,7 @@ extension RunAnywhere {
243244
// Resolve actual model path
244245
let modelPath = try resolveModelFilePath(for: modelInfo)
245246
let logger = SDKLogger(category: "RunAnywhere.STT")
246-
logger.info("Loading STT model from resolved path: \(modelPath.path)")
247+
logger.info("Loading STT model from resolved path: \(modelPath.lastPathComponent)")
247248
try await CppBridge.STT.shared.loadModel(modelPath.path, modelId: modelId, modelName: modelInfo.name)
248249
}
249250

@@ -278,7 +279,7 @@ extension RunAnywhere {
278279
// Resolve actual model path
279280
let modelPath = try resolveModelFilePath(for: modelInfo)
280281
let logger = SDKLogger(category: "RunAnywhere.TTS")
281-
logger.info("Loading TTS voice from resolved path: \(modelPath.path)")
282+
logger.info("Loading TTS voice from resolved path: \(modelPath.lastPathComponent)")
282283
try await CppBridge.TTS.shared.loadVoice(modelPath.path, voiceId: voiceId, voiceName: modelInfo.name)
283284
}
284285

0 commit comments

Comments
 (0)