Skip to content

Commit 15327a5

Browse files
committed
repl: create history file with mode 0600
1 parent 6d6bc5d commit 15327a5

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/internal/repl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
8888
var writing = false;
8989
var pending = false;
9090
repl.pause();
91-
fs.open(historyPath, 'a+', oninit);
91+
fs.open(historyPath, 'a+', 0o0600, oninit);
9292

9393
function oninit(err, hnd) {
9494
if (err) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
if (common.isWindows) {
6+
console.log('1..0 # Skipped: Win32 uses ACLs for file permissions, ' +
7+
'modes are always 0666 and says nothing about group/other ' +
8+
'read access.');
9+
return;
10+
}
11+
12+
const assert = require('assert');
13+
const path = require('path');
14+
const fs = require('fs');
15+
const child_process = require('child_process');
16+
17+
// Invoking the REPL should create a repl history file at the specified path
18+
// and a mode not readable by group/others.
19+
20+
common.refreshTmpDir();
21+
const replHistoryPath = path.join(common.tmpDir, '.node_repl_history');
22+
23+
child_process.execFileSync(process.execPath, ['-i'], {
24+
env: { NODE_REPL_HISTORY: replHistoryPath },
25+
stdio: ['ignore', 'pipe', 'inherit']
26+
});
27+
28+
const stat = fs.statSync(replHistoryPath);
29+
assert.strictEqual(
30+
stat.mode & 0o77, 0,
31+
'REPL history file should not be accessible by group/others');

0 commit comments

Comments
 (0)