Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd919d22

Browse files
committed
fix(exec): lockdown file permissions (#1060)
This locks down file permissions used by the internal implementation of`shell.exec()`.Issue#1058Tested manually using the documented scenarios
1 parentfcf1651 commitd919d22

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

‎src/exec.js‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,24 @@ function execSync(cmd, opts, pipe) {
4848
stderrFile:stderrFile,
4949
};
5050

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+
functionwriteFileLockedDown(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));
5269

5370
varexecArgs=[
5471
path.join(__dirname,'exec-child.js'),
@@ -91,6 +108,7 @@ function execSync(cmd, opts, pipe) {
91108
}
92109

93110
// 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).
94112
try{common.unlinkSync(paramsFile);}catch(e){}
95113
try{common.unlinkSync(stderrFile);}catch(e){}
96114
try{common.unlinkSync(stdoutFile);}catch(e){}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp