@@ -285,6 +285,7 @@ export async function writeSessionFile(pid: string, pipePath: string) {
285285 await fs . ensureDir ( sessionsDir ) ;
286286 const filePath = path . join ( sessionsDir , `${ pid } .json` ) ;
287287 await fs . writeJson ( filePath , { pipe : pipePath } ) ;
288+ await setOwnerOnlyPermissions ( filePath ) ;
288289}
289290
290291async function updateActiveTerminalFiles ( pipePath : string ) {
@@ -299,6 +300,14 @@ async function updateActiveTerminalFiles(pipePath: string) {
299300 }
300301}
301302
303+ async function setOwnerOnlyPermissions ( filePath : string ) : Promise < void > {
304+ if ( process . platform === 'win32' ) {
305+ return ;
306+ }
307+
308+ await fs . chmod ( filePath , 0o600 ) ;
309+ }
310+
302311function makePipePath ( ) : string {
303312 const suffix = crypto . randomBytes ( 8 ) . toString ( 'hex' ) ;
304313 if ( process . platform === 'win32' ) {
@@ -381,10 +390,12 @@ export async function getGlobalPipePath(): Promise<string> {
381390 } ) ;
382391
383392 server . listen ( pipePath , ( ) => {
384- globalPipePath = pipePath ;
385- globalSessionServer = server ;
386- console . info ( `[SessionServer] Listening on ${ pipePath } ` ) ;
387- resolve ( pipePath ) ;
393+ void setOwnerOnlyPermissions ( pipePath ) . then ( ( ) => {
394+ globalPipePath = pipePath ;
395+ globalSessionServer = server ;
396+ console . info ( `[SessionServer] Listening on ${ pipePath } ` ) ;
397+ resolve ( pipePath ) ;
398+ } ) . catch ( reject ) ;
388399 } ) ;
389400 } ) ;
390401}
@@ -429,7 +440,8 @@ export async function getAttachSessionCommand(): Promise<string> {
429440 const sessPath = extensionContext . asAbsolutePath ( 'sess' ) . replace ( / \\ / g, '/' ) ;
430441 const installSessScriptPath = extensionContext . asAbsolutePath ( path . join ( 'R' , 'install_sess.R' ) ) . replace ( / \\ / g, '/' ) ;
431442 const scriptPath = getAttachSessionScriptPath ( pipePath ) ;
432- await fs . writeFile ( scriptPath , buildAttachSessionScript ( pipePath , sessPath , installSessScriptPath ) , { encoding : 'utf-8' } ) ;
443+ await fs . writeFile ( scriptPath , buildAttachSessionScript ( pipePath , sessPath , installSessScriptPath ) , { encoding : 'utf-8' , mode : 0o600 } ) ;
444+ await setOwnerOnlyPermissions ( scriptPath ) ;
433445 attachSessionScriptPath = scriptPath ;
434446
435447 return `source(${ asRStringLiteral ( scriptPath ) } )` ;
0 commit comments