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

Changed default file modes from 0o644 to 0o600 for better security #1141

Merged
merged 1 commit into from Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/dateFile.md
Expand Up @@ -11,7 +11,7 @@ This is a file appender that rolls log files based on a configurable time, rathe

Any other configuration parameters will be passed to the underlying [streamroller](https://github.com/nomiddlename/streamroller) implementation (see also node.js core file streams):
* `encoding` - `string` (default "utf-8")
* `mode`- `integer` (default 0o644 - [node.js file modes](https://nodejs.org/dist/latest-v12.x/docs/api/fs.html#fs_file_modes))
* `mode`- `integer` (default 0o600 - [node.js file modes](https://nodejs.org/dist/latest-v12.x/docs/api/fs.html#fs_file_modes))
* `flags` - `string` (default 'a')
* `compress` - `boolean` (default false) - compress the backup files during rolling (backup files will have `.gz` extension)
* `alwaysIncludePattern` - `boolean` (default false) - include the pattern in the name of the current log file as well as the backups.
Expand Down
2 changes: 1 addition & 1 deletion docs/file.md
Expand Up @@ -12,7 +12,7 @@ The file appender writes log events to a file. It supports an optional maximum f

Any other configuration parameters will be passed to the underlying [streamroller](https://github.com/nomiddlename/streamroller) implementation (see also node.js core file streams):
* `encoding` - `string` (default "utf-8")
* `mode`- `integer` (default 0o644 - [node.js file modes](https://nodejs.org/dist/latest-v12.x/docs/api/fs.html#fs_file_modes))
* `mode`- `integer` (default 0o600 - [node.js file modes](https://nodejs.org/dist/latest-v12.x/docs/api/fs.html#fs_file_modes))
* `flags` - `string` (default 'a')
* `compress` - `boolean` (default false) - compress the backup files during rolling (backup files will have `.gz` extension)
* `keepFileExt` - `boolean` (default false) - preserve the file extension when rotating log files (`file.log` becomes `file.1.log` instead of `file.log.1`)
Expand Down
2 changes: 1 addition & 1 deletion docs/fileSync.md
Expand Up @@ -12,7 +12,7 @@ The sync file appender writes log events to a file, the only difference to the n

Any other configuration parameters will be passed to the underlying node.js core stream implementation:
* `encoding` - `string` (default "utf-8")
* `mode`- `integer` (default 0644)
* `mode`- `integer` (default 0600)
* `flags` - `string` (default 'a')

## Example
Expand Down
4 changes: 3 additions & 1 deletion lib/appenders/dateFile.js
Expand Up @@ -49,7 +49,6 @@ function appender(

function configure(config, layouts) {
let layout = layouts.basicLayout;

if (config.layout) {
layout = layouts.layout(config.layout.type, config.layout);
}
Expand All @@ -58,6 +57,9 @@ function configure(config, layouts) {
config.alwaysIncludePattern = false;
}

// security default (instead of relying on streamroller default)
config.mode = config.mode || 0o600;

return appender(
config.filename,
config.pattern,
Expand Down
3 changes: 3 additions & 0 deletions lib/appenders/file.js
Expand Up @@ -110,6 +110,9 @@ function configure(config, layouts) {
layout = layouts.layout(config.layout.type, config.layout);
}

// security default (instead of relying on streamroller default)
config.mode = config.mode || 0o600;

return fileAppender(
config.filename,
layout,
Expand Down
2 changes: 1 addition & 1 deletion lib/appenders/fileSync.js
Expand Up @@ -192,7 +192,7 @@ function configure(config, layouts) {
const options = {
flags: config.flags || 'a',
encoding: config.encoding || 'utf8',
mode: config.mode || 0o644
mode: config.mode || 0o600
};

return fileAppender(
Expand Down