Skip to content

Bug: Values in errors are no longer masked #214

@Trolleymusic

Description

@Trolleymusic

Describe the bug
When logging errors with additional properties, the values are not masked

To Reproduce
Steps to reproduce the behavior:

const error = new Error();
Object.assign(error, {
  extensions: {
    serviceName: 'upstream-service',
    variables: {
      firstName: 'foo',
      phoneNumber: 'bar'
    }
  }
});

const log = new Logger({
  maskValuesOfKeys: ["firstName", "phoneNumber"],
  type: "json"
})

log.info(error);

Outputs:

{
  "nativeError": {
    "extensions": {
      "serviceName": "upstream-service",
      "variables": {
        "firstName": "foo",
        "phoneNumber": "bar"
      }
    }
  },
  "name": "Error",
  "message": "Example error",
  "stack": [ ],
  "_meta": { }
}

(stack and _meta are outputting properly, I'm just truncating them for the report.)

Expected behavior
Properties and sub-properties of Errors should be masked, eg:

{
  "nativeError": {
    "extensions": {
      "serviceName": "upstream-service",
      "variables": {
        "firstName": "[***]",
        "phoneNumber": "[***]"
      }
    }
  },
  "name": "Error",
  "message": "Example error",
  "stack": [ ],
  "_meta": { }
}

Additional context
The expected behaviour was the default behaviour previously, there seems to have been a change introduced in v4.4.0. The observed issue occurs with all versions from v4.4.0 to v4.7.2. The output of v4.3.1 is consistent with the expected output.

{
  "nativeError": {
    "extensions": {
      "serviceName": "upstream-service",
      "variables": {
        "firstName": "[***]",
        "phoneNumber": "[***]"
      }
    }
  },
  "name": "Error",
  "message": "Example error",
  "stack": [ ],
  "_meta": { }
}

Node.js Version
e.g. 16.16.0

OS incl. Version
e.g. macOS 13.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions