@@ -48,7 +48,24 @@ function execSync(cmd, opts, pipe) {
48
48
stderrFile : stderrFile ,
49
49
} ;
50
50
51
- fs . writeFileSync ( paramsFile , JSON . stringify ( paramsToSerialize ) , 'utf8' ) ;
51
+ // Create the files and ensure these are locked down (for read and write) to
52
+ // the current user. The main concerns here are:
53
+ //
54
+ // * If we execute a command which prints sensitive output, then
55
+ // stdoutFile/stderrFile must not be readable by other users.
56
+ // * paramsFile must not be readable by other users, or else they can read it
57
+ // to figure out the path for stdoutFile/stderrFile and create these first
58
+ // (locked down to their own access), which will crash exec() when it tries
59
+ // to write to the files.
60
+ function writeFileLockedDown ( filePath , data ) {
61
+ fs . writeFileSync ( filePath , data , {
62
+ encoding : 'utf8' ,
63
+ mode : parseInt ( '600' , 8 ) ,
64
+ } ) ;
65
+ }
66
+ writeFileLockedDown ( stdoutFile , '' ) ;
67
+ writeFileLockedDown ( stderrFile , '' ) ;
68
+ writeFileLockedDown ( paramsFile , JSON . stringify ( paramsToSerialize ) ) ;
52
69
53
70
var execArgs = [
54
71
path . join ( __dirname , 'exec-child.js' ) ,
@@ -91,6 +108,7 @@ function execSync(cmd, opts, pipe) {
91
108
}
92
109
93
110
// No biggie if we can't erase the files now -- they're in a temp dir anyway
111
+ // and we locked down permissions (see the note above).
94
112
try { common . unlinkSync ( paramsFile ) ; } catch ( e ) { }
95
113
try { common . unlinkSync ( stderrFile ) ; } catch ( e ) { }
96
114
try { common . unlinkSync ( stdoutFile ) ; } catch ( e ) { }
0 commit comments