@@ -58,7 +58,24 @@ function execSync(cmd, opts, pipe) {
58
58
stderrFile : stderrFile ,
59
59
} ;
60
60
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 ) ) ;
62
79
63
80
var execArgs = [
64
81
path . join ( __dirname , 'exec-child.js' ) ,
@@ -101,6 +118,7 @@ function execSync(cmd, opts, pipe) {
101
118
}
102
119
103
120
// 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).
104
122
try { common . unlinkSync ( paramsFile ) ; } catch ( e ) { }
105
123
try { common . unlinkSync ( stderrFile ) ; } catch ( e ) { }
106
124
try { common . unlinkSync ( stdoutFile ) ; } catch ( e ) { }
0 commit comments