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

Redacting still modifies original data #1997

Open
azakero opened this issue Jul 1, 2024 · 2 comments
Open

Redacting still modifies original data #1997

azakero opened this issue Jul 1, 2024 · 2 comments

Comments

@azakero
Copy link

azakero commented Jul 1, 2024

Version:

"pino": "^8.7.0",
"pino-pretty": "^9.1.1"

Hi. I'm not sure if this was fixed or not but I'm still facing the issue where redacting modifies the original data. Here is an example:

Redaction: ['.customer.name', '.customer.age', '*.customer.address'].

const data = {
  customer: {
    name: 'John',
    age: 23,
    address: '221B Baker Street'
  }
}

logger.info({ data }, 'Data');

console.log(data);

Output:

{
  customer: {
    name: '[Redacted]',
    age: '[Redacted]',
    address: '[Redacted]'
  }
}

Can someone please tell me if this was fixed and which version is it available from?

@mcollina
Copy link
Member

mcollina commented Jul 1, 2024

Can you create a complete example? Thanks

@victorkirov
Copy link

victorkirov commented Nov 29, 2024

Here's a full example. It's kinda weird.

This breaks:

import pino from "pino";

const data = {
  customer: {
    name: "John",
    age: 23,
    address: "221B Baker Street",
    things: [
      {
        name: "Phone",
      },
      {
        name: "Laptop",
      },
      "bloop",
    ],
  },
};

const logger = pino({
  redact: {
    paths: [
      "data.customer.things[*].name",
      "data.customer.things[*]", 
    ],
    censor: (value, path) => {
      if (path[path.length - 1] === "name") {
        return value.substring(0, 2) + "_REDACTED";
      }

      return "[REDACTED]";
    },
  },
});

logger.info({ data }, "Data");

console.log(JSON.stringify(data));
// {"customer":{"name":"John","age":23,"address":"221B Baker Street","things":[{"name":"Ph_REDACTED"},{"name":"La_REDACTED"},"bloop"]}}

If you swap the order of the redact definitions then all is good:

import pino from "pino";

const data = {
  customer: {
    name: "John",
    age: 23,
    address: "221B Baker Street",
    things: [
      {
        name: "Phone",
      },
      {
        name: "Laptop",
      },
      "bloop",
    ],
  },
};

const logger = pino({
  redact: {
    paths: [
      "data.customer.things[*]", 
      "data.customer.things[*].name",
    ],
    censor: (value, path) => {
      if (path[path.length - 1] === "name") {
        return value.substring(0, 2) + "_REDACTED";
      }

      return "[REDACTED]";
    },
  },
});

logger.info({ data }, "Data");

console.log(JSON.stringify(data));

// {"customer":{"name":"John","age":23,"address":"221B Baker Street","things":[{"name":"Phone"},{"name":"Laptop"},"bloop"]}}

In both cases, the log output is:
{"level":30,"time":1732883164360,"pid":94514,"hostname":"host.local","data":{"customer":{"name":"John","age":23,"address":"221B Baker Street","things":["[REDACTED]","[REDACTED]","[REDACTED]"]}},"msg":"Data"}

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

No branches or pull requests

3 participants