Skip to content

Commit

Permalink
Changed default file modes from 0o644 to 0o600 for better security (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
lamweili authored Jan 16, 2022
1 parent cd1617c commit 8c1deca
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The streams behave the same as standard node.js streams, except that when certai
* `numBackups` \<integer\> - defaults to `1` - the number of old files to keep (excluding the hot file)
* `options` \<Object\>
* `encoding` \<string\> - defaults to `'utf8'`
* `mode` \<integer\> - defaults to `0o644`
* `mode` \<integer\> - defaults to `0o600`
* `flags` \<string\> - defaults to `'a'` (see [fs.open](https://nodejs.org/dist/latest-v8.x/docs/api/fs.html#fs_fs_open_path_flags_mode_callback) for more details)
* `compress` \<boolean\> - defaults to `false` - compress the backup files using gzip (files will have `.gz` extension).
* `keepFileExt` \<boolean\> - defaults to `false` - keep the file original extension. e.g.: `abc.log -> abc.1.log`.
Expand All @@ -51,7 +51,7 @@ When filename size >= maxSize then:
* `pattern` \<string\> - defaults to `yyyy-MM-dd` - the date pattern to trigger rolling (see below)
* `options` \<Object\>
* `encoding` \<string\> - defaults to `'utf8'`
* `mode` \<integer\> - defaults to `0o644`
* `mode` \<integer\> - defaults to `0o600`
* `flags` \<string\> - defaults to `'a'` (see [fs.open](https://nodejs.org/dist/latest-v8.x/docs/api/fs.html#fs_fs_open_path_flags_mode_callback) for more details)
* `compress` \<boolean\> - defaults to `false` - compress the backup files using gzip (files will have `.gz` extension).
* `keepFileExt` \<boolean\> - defaults to `false` - keep the file original extension. e.g.: `abc.log -> abc.2013-08-30.log`.
Expand Down
4 changes: 2 additions & 2 deletions lib/RollingFileWriteStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RollingFileWriteStream extends Writable {
* @param {number} options.numToKeep - The max numbers of files to keep.
* @param {number} options.maxSize - The maxSize one file can reach. Unit is Byte.
* This should be more than 1024. The default is Number.MAX_SAFE_INTEGER.
* @param {string} options.mode - The mode of the files. The default is '0644'. Refer to stream.writable for more.
* @param {string} options.mode - The mode of the files. The default is '0600'. Refer to stream.writable for more.
* @param {string} options.flags - The default is 'a'. Refer to stream.flags for more.
* @param {boolean} options.compress - Whether to compress backup files.
* @param {boolean} options.keepFileExt - Whether to keep the file extension.
Expand Down Expand Up @@ -94,7 +94,7 @@ class RollingFileWriteStream extends Writable {
maxSize: Number.MAX_SAFE_INTEGER,
numToKeep: Number.MAX_SAFE_INTEGER,
encoding: "utf8",
mode: parseInt("0644", 8),
mode: parseInt("0600", 8),
flags: "a",
compress: false,
keepFileExt: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/moveAndMaybeCompressFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const zlib = require('zlib');

const _parseOption = function(rawOptions){
const defaultOptions = {
mode: parseInt("0644", 8),
mode: parseInt("0600", 8),
compress: false,
};
const options = Object.assign({}, defaultOptions, rawOptions);
Expand Down
2 changes: 1 addition & 1 deletion test/DateRollingFileStream-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("DateRollingFileStream", function() {
});

it("with default settings for the underlying stream", function() {
stream.currentFileStream.mode.should.eql(420);
stream.currentFileStream.mode.should.eql(0o600);
stream.currentFileStream.flags.should.eql("a");
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/RollingFileStream-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe("RollingFileStream", function() {
});

it("should apply default settings to the underlying stream", function() {
stream.theStream.mode.should.eql(420);
stream.theStream.mode.should.eql(0o600);
stream.theStream.flags.should.eql("a");
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/RollingFileWriteStream-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ describe("RollingFileWriteStream", () => {
it("should take a filename and options, return Writable", () => {
s.should.be.an.instanceOf(stream.Writable);
s.currentFileStream.path.should.eql(fileObj.path);
s.currentFileStream.mode.should.eql(420);
s.currentFileStream.mode.should.eql(0o600);
s.currentFileStream.flags.should.eql("a");
});

it("should apply default options", () => {
s.options.maxSize.should.eql(Number.MAX_SAFE_INTEGER);
s.options.encoding.should.eql("utf8");
s.options.mode.should.eql(420);
s.options.mode.should.eql(0o600);
s.options.flags.should.eql("a");
s.options.compress.should.eql(false);
s.options.keepFileExt.should.eql(false);
Expand Down

0 comments on commit 8c1deca

Please sign in to comment.