Skip to content

Commit 6353579

Browse files
XeCycleevanlucas
authored andcommitted
repl: create history file with mode 0600
Set the mode bits on the history file to 0o600 instead of leaving it unspecified, which resulted in 0o755 on Unices. Test code mostly written by Trott: #3392 (comment). PR-URL: #3394Fixes: #3392 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 49af20c commit 6353579

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

‎lib/internal/repl.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
9393
varwriting=false;
9494
varpending=false;
9595
repl.pause();
96-
fs.open(historyPath,'a+',oninit);
96+
// History files are conventionally not readable by others:
97+
// https://github.com/nodejs/node/issues/3392
98+
// https://github.com/nodejs/node/pull/3394
99+
fs.open(historyPath,'a+',0o0600,oninit);
97100

98101
functiononinit(err,hnd){
99102
if(err){
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
// Flags: --expose_internals
3+
4+
constcommon=require('../common');
5+
6+
if(common.isWindows){
7+
console.log('1..0 # Skipped: Win32 uses ACLs for file permissions, '+
8+
'modes are always 0666 and says nothing about group/other '+
9+
'read access.');
10+
return;
11+
}
12+
13+
constassert=require('assert');
14+
constpath=require('path');
15+
constfs=require('fs');
16+
constrepl=require('internal/repl');
17+
constDuplex=require('stream').Duplex;
18+
// Invoking the REPL should create a repl history file at the specified path
19+
// and mode 600.
20+
21+
varstream=newDuplex();
22+
stream.pause=stream.resume=function(){};
23+
// ends immediately
24+
stream._read=function(){
25+
this.push(null);
26+
};
27+
stream._write=function(c,e,cb){
28+
cb();
29+
};
30+
stream.readable=stream.writable=true;
31+
32+
common.refreshTmpDir();
33+
constreplHistoryPath=path.join(common.tmpDir,'.node_repl_history');
34+
35+
constcheckResults=common.mustCall(function(err,r){
36+
if(err)
37+
throwerr;
38+
r.input.end();
39+
conststat=fs.statSync(replHistoryPath);
40+
assert.strictEqual(
41+
stat.mode&0o777,0o600,
42+
'REPL history file should be mode 0600');
43+
});
44+
45+
repl.createInternalRepl(
46+
{NODE_REPL_HISTORY: replHistoryPath},
47+
{
48+
terminal: true,
49+
input: stream,
50+
output: stream
51+
},
52+
checkResults
53+
);

0 commit comments

Comments
 (0)