@@ -269,8 +269,9 @@ async function ensureIpcDirectory(filePath: string): Promise<void> {
269269 const fs = getFs ( )
270270 const path = getPath ( )
271271 const dir = path . dirname ( filePath )
272- // Create directory recursively if it doesn't exist.
273- await fs . promises . mkdir ( dir , { recursive : true } )
272+ // Use restrictive permissions (owner-only) to prevent other users
273+ // from reading or writing IPC stub files.
274+ await fs . promises . mkdir ( dir , { recursive : true , mode : 0o700 } )
274275}
275276
276277/**
@@ -326,11 +327,12 @@ export async function writeIpcStub(
326327
327328 // Write with pretty printing for debugging.
328329 const fs = getFs ( )
329- await fs . promises . writeFile (
330- stubPath ,
331- JSON . stringify ( validated , null , 2 ) ,
332- 'utf8' ,
333- )
330+ // Use restrictive permissions (owner-only read/write) to prevent
331+ // other users on the system from reading sensitive IPC data.
332+ await fs . promises . writeFile ( stubPath , JSON . stringify ( validated , null , 2 ) , {
333+ encoding : 'utf8' ,
334+ mode : 0o600 ,
335+ } )
334336 return stubPath
335337}
336338
@@ -442,7 +444,9 @@ export async function cleanupIpcStubs(appName: string): Promise<void> {
442444 // File is stale if EITHER check indicates staleness
443445 isStale = isStale || contentAge > maxAgeMs
444446 } catch {
445- // If we can't read/parse the file, rely on mtime check
447+ // If we can't read/parse the file, treat it as stale
448+ // to prevent accumulation of corrupted stub files.
449+ isStale = true
446450 }
447451
448452 if ( isStale ) {
0 commit comments