Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: create history file with mode 0600. #3394

Closed
wants to merge 1 commit into from

Conversation

XeCycle
Copy link
Contributor

@XeCycle XeCycle commented Oct 16, 2015

Test code mostly written by Trott
#3392 (comment).

@@ -88,7 +88,7 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
var writing = false;
var pending = false;
repl.pause();
fs.open(historyPath, 'a+', oninit);
fs.open(historyPath, 'a+', /* 0600 */ 384, oninit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use an octal literal: 0o0600

@ChALkeR ChALkeR added the repl Issues and PRs related to the REPL subsystem. label Oct 16, 2015
@Trott
Copy link
Member

Trott commented Oct 16, 2015

LGTM if CI is happy.

@Trott
Copy link
Member

Trott commented Oct 16, 2015

Fixes: #3392

@Trott
Copy link
Member

Trott commented Oct 16, 2015

@Trott
Copy link
Member

Trott commented Oct 16, 2015

@XeCycle
Copy link
Contributor Author

XeCycle commented Oct 17, 2015

Tried it on Windows, and the returned stat is 010666. I guess that's because Windows uses a different permission model; do you think it okay to skip this test on Windows?

@rvagg
Copy link
Member

rvagg commented Oct 17, 2015

I think so but lets ask @nodejs/platform-windows

@Trott
Copy link
Member

Trott commented Oct 17, 2015

I changed

  assert.strictEqual(mode, '0600', 'REPL history file should be mode 0600');

To just this

  assert.strictEqual(mode, '0600');

So that it would report the actual value. Result is here.

So, Windows is creating the file with mode 0666 rather than 0600.

The question is: Is this a bug in the code that creates the file or is it a limitation of running the Node.js REPL on the Windows operating system?

@Trott
Copy link
Member

Trott commented Oct 17, 2015

The code uses fs.open() to set the mode on file creation, so I guess if there's stuff that does not completely work there, a Windows libuv person would know the deal?

@Trott
Copy link
Member

Trott commented Oct 17, 2015

This comment in the libuv source would seem to be more-or-less a smoking gun. I think you can just check common.isWindows() at the top of the test, and if it is Windows, skip the test. You can emulate other tests like this from test-process-remove-all-signal-listeners:

if (common.isWindows) {
  console.log('1..0 # Skipped: Win32 doesn\'t have signals, just a kind of ' +
              'emulation, insufficient for this test to apply.');
  return;
}

@XeCycle
Copy link
Contributor Author

XeCycle commented Oct 17, 2015

From docs of CreateFile:

  • The access control lists (ACL) in the default security descriptor for a file or directory are inherited from its parent directory.

So privacy on the history file relies on the user having a fine ACL in his/her home directory (which appers to be like C:\Users\username).

@Trott
Copy link
Member

Trott commented Oct 17, 2015

Cool. LGTM if CI passes.

CI: https://ci.nodejs.org/job/node-test-commit/865/

@Trott
Copy link
Member

Trott commented Oct 17, 2015

All test failures are just the unrelated usual suspects and something weird with OS X such that it won't even build or something.

In other words: 👍

Hopefully someone else can give it an LGTM too.


const checkResults = common.mustCall(function(err, r) {
if (err)
throw err;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use assert.ifError instead of this if block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there are other tests writing if (err) throw err; e.g. test-fs-write. Does the current style explicitly prefer assert.ifError? If not I think this if block is also okay.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to use assert here, this is common practice.

@Fishrock123
Copy link
Contributor

Seems fine to me.

@Trott
Copy link
Member

Trott commented Oct 19, 2015

@Fishrock123 Does that constitute an LGTM?

stream.readable = stream.writable = true;

common.refreshTmpDir();
const replHistoryPath = path.join(common.tmpDir, 'repl_history');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this consistent with the other test? '.node_repl_history'

@XeCycle
Copy link
Contributor Author

XeCycle commented Oct 21, 2015

@Fishrock123 file name changed, not rebasing.

@XeCycle
Copy link
Contributor Author

XeCycle commented Nov 3, 2015

Please check this commit. Discovered we have -i/--interactive, so tried testing with that, but it fails because of another check here and here. Is it intended that a forced interactive session without terminal does not create a history file?

@Fishrock123
Copy link
Contributor

Discovered we have -i/--interactive, so tried testing with that, but it fails because of another check here and here. Is it intended that a forced interactive session without terminal does not create a history file?

Undefined. -i/--interactive should act just like the regular repl as much as possible though imo.

@jasnell
Copy link
Member

jasnell commented Apr 22, 2016

What's the status on this one?

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Apr 22, 2016
@XeCycle
Copy link
Contributor Author

XeCycle commented Apr 22, 2016

Seems like maintainers did not agree on the tests. Anyway there are no conflicts, a rebase is easy, so let me know if you want this landed.

@jasnell
Copy link
Member

jasnell commented Apr 22, 2016

@nodejs/collaborators @nodejs/ctc ... does anyone have any further thoughts on this one?
@XeCycle ... if you'd like to rebase I'll see if I can get an updated review.

@Fishrock123
Copy link
Contributor

@Fishrock123
Copy link
Contributor

ci is green, I can't really make an informative opinion about this though

@silverwind
Copy link
Contributor

600 is the right mode for history files, it protects the content from other users in case the home directory is readable. The test seems a bit overly complicated, but overall LGTM.

@Fishrock123
Copy link
Contributor

Ok, LGTM then

@santigimeno
Copy link
Member

LGTM

@@ -93,7 +93,7 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
var writing = false;
var pending = false;
repl.pause();
fs.open(historyPath, 'a+', oninit);
fs.open(historyPath, 'a+', 0o0600, oninit);
Copy link
Member

@jasnell jasnell May 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Would you mind adding a quick code comment with a quick explanation here. Nothing complicated, just enough for someone scanning through to know why the flag was set to this.

@jasnell
Copy link
Member

jasnell commented May 3, 2016

Added a couple of comments that I'd like to see addressed before this lands. Otherwise LGTM

@jasnell jasnell removed the stalled Issues and PRs that are stalled. label May 3, 2016
@jasnell
Copy link
Member

jasnell commented May 3, 2016

What semver-iness would this be? I'm thinking just a patch (because I'd consider this a bug fix) but figured I'd ask.

@Fishrock123
Copy link
Contributor

I don't think it would be major.

@XeCycle
Copy link
Contributor Author

XeCycle commented May 4, 2016

@jasnell

Would you mind adding a quick code comment with a quick explanation here

Added, pointing to this PR and issue.

Personally I prefer the masked version

Me too, changed it to the masked version.

@jasnell
Copy link
Member

jasnell commented May 4, 2016

@jasnell
Copy link
Member

jasnell commented May 4, 2016

LGTM if CI is green

silverwind pushed a commit that referenced this pull request May 4, 2016
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: #3394
Fixes: #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>
@silverwind
Copy link
Contributor

Thanks you! Landed in b72d048.

@silverwind silverwind closed this May 4, 2016
evanlucas pushed a commit that referenced this pull request May 17, 2016
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: #3394
Fixes: #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>
MylesBorins pushed a commit that referenced this pull request Jun 1, 2016
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: #3394
Fixes: #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>
MylesBorins pushed a commit that referenced this pull request Jun 23, 2016
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: #3394
Fixes: #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>
MylesBorins pushed a commit that referenced this pull request Jun 24, 2016
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: #3394
Fixes: #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>
@MylesBorins MylesBorins mentioned this pull request Jun 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.