@@ -155,16 +155,20 @@ enum ConnectionExportService {
155155 let aiPolicy : String ? = connection. aiPolicy? . rawValue
156156
157157 // Filter secure fields from additionalFields
158- var filteredFields = connection. additionalFields
159- let secureFieldIds = PluginMetadataRegistry . shared
160- . snapshot ( forTypeId: connection. type. pluginTypeId) ?
161- . connection. additionalConnectionFields
162- . filter ( \. isSecure)
163- . map ( \. id) ?? [ ]
164- for fieldId in secureFieldIds {
165- filteredFields. removeValue ( forKey: fieldId)
158+ // If plugin metadata is unavailable, omit all fields to avoid leaking secrets
159+ let additionalFields : [ String : String ] ?
160+ if let snapshot = PluginMetadataRegistry . shared. snapshot ( forTypeId: connection. type. pluginTypeId) {
161+ var filteredFields = connection. additionalFields
162+ let secureFieldIds = snapshot. connection. additionalConnectionFields
163+ . filter ( \. isSecure)
164+ . map ( \. id)
165+ for fieldId in secureFieldIds {
166+ filteredFields. removeValue ( forKey: fieldId)
167+ }
168+ additionalFields = filteredFields. isEmpty ? nil : filteredFields
169+ } else {
170+ additionalFields = nil
166171 }
167- let additionalFields : [ String : String ] ? = filteredFields. isEmpty ? nil : filteredFields
168172
169173 let exportable = ExportableConnection (
170174 name: connection. name,
@@ -222,10 +226,12 @@ enum ConnectionExportService {
222226 encoder. outputFormatting = [ . prettyPrinted, . sortedKeys]
223227 encoder. dateEncodingStrategy = . iso8601
224228
225- guard let data = try ? encoder. encode ( envelope) else {
229+ do {
230+ return try encoder. encode ( envelope)
231+ } catch {
232+ logger. error ( " Encoding failed: \( error) " )
226233 throw ConnectionExportError . encodingFailed
227234 }
228- return data
229235 }
230236
231237 static func exportConnections( _ connections: [ DatabaseConnection ] , to url: URL ) throws {
0 commit comments