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

Add support for secrets/sensitive-info filtering #78

Merged
merged 1 commit into from
Feb 24, 2019

Conversation

klaudiosinani
Copy link
Owner

@klaudiosinani klaudiosinani commented Feb 24, 2019

Description

The PR introduces the ability to filter out secrets/sensitive-info from the body & metadata, i.e. scope name etc, of to-be-logged messages. The feature can be utilized through the secrets option, which is part of the configuration object passed to a Signale instance on initialization. The option is of type Array<String|Number> and can hold multiple secrets, all of which are removed, if present, from the to-be-logged messages and replaced with the default '[secure]' string. Additionally, when the unary signale.scope(name) function is used, the returned Signale instance inherits all the secrets belonging to its parent. The secrets checking process is performed in a case-sensitive manner. Finally, this PR is a follow-up to #71.

It is critical and highly recommended to not type directly secrets in your code, thus the following example serves only as a simple & easily reproducible usage demonstration.

// foo.js
'use strict';
const {Signale} = require('signale');

// In reality secrets could be securely fetched/decrypted through a dedicated API 
const [USERNAME, TOKEN] = ['klaussinani', 'token'];

const logger = new Signale({
  secrets: [USERNAME, TOKEN]
});

logger.log('$ export USERNAME=%s', USERNAME);
//=> $ export USERNAME=[secure]
logger.log('$ export TOKEN=%s', TOKEN);
//=> $ export TOKEN=[secure]

// `logger1` inherits all secrets from its parent `logger`
const logger1 = logger.scope('parent');

logger1.log('$ export USERNAME=%s', USERNAME);
//=> [parent] › $ export USERNAME=[secure]
logger1.log('$ export TOKEN=%s', TOKEN);
//=> [parent] › $ export TOKEN=[secure]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant