@@ -58,7 +58,24 @@ function execSync(cmd, opts, pipe) {
5858 stderrFile : stderrFile ,
5959 } ;
6060
61- fs . writeFileSync ( paramsFile , JSON . stringify ( paramsToSerialize ) , 'utf8' ) ;
61+ // Create the files and ensure these are locked down (for read and write) to
62+ // the current user. The main concerns here are:
63+ //
64+ // * If we execute a command which prints sensitive output, then
65+ // stdoutFile/stderrFile must not be readable by other users.
66+ // * paramsFile must not be readable by other users, or else they can read it
67+ // to figure out the path for stdoutFile/stderrFile and create these first
68+ // (locked down to their own access), which will crash exec() when it tries
69+ // to write to the files.
70+ function writeFileLockedDown ( filePath , data ) {
71+ fs . writeFileSync ( filePath , data , {
72+ encoding : 'utf8' ,
73+ mode : parseInt ( '600' , 8 ) ,
74+ } ) ;
75+ }
76+ writeFileLockedDown ( stdoutFile , '' ) ;
77+ writeFileLockedDown ( stderrFile , '' ) ;
78+ writeFileLockedDown ( paramsFile , JSON . stringify ( paramsToSerialize ) ) ;
6279
6380 var execArgs = [
6481 path . join ( __dirname , 'exec-child.js' ) ,
@@ -101,6 +118,7 @@ function execSync(cmd, opts, pipe) {
101118 }
102119
103120 // No biggie if we can't erase the files now -- they're in a temp dir anyway
121+ // and we locked down permissions (see the note above).
104122 try { common . unlinkSync ( paramsFile ) ; } catch ( e ) { }
105123 try { common . unlinkSync ( stderrFile ) ; } catch ( e ) { }
106124 try { common . unlinkSync ( stdoutFile ) ; } catch ( e ) { }
0 commit comments