created_at and updated_at are scrubbed away
hckhanh opened this issue · 7 comments
This is my data
{
"created_at": "2020-06-09T07:51:58.000Z",
"password": "abcd",
"secret": "secret",
"project_id": 1,
"updated_at": "2020-06-09T07:51:58.000Z"
}
When I try to use this config
const scrubberConfig = {
fields: {
password: {
scrubber: "staticScrubber",
params: {
replacement: "***"
}
},
secret: {
scrubber: "staticScrubber",
params: {
replacement: "***"
}
}
},
throwOnError: true, // default: false,
preserveFalsy: false // default: true
};
It does scrubber the secrets, but the created_at
and updated_at
will become to {}
{
"created_at": {},
"password": "***",
"secret": "***",
"project_id": 1,
"updated_at": {}
}
@hckhanh can you post a snippet of your code?
When I try
import { ScrubberConfig, Scrubber } from '@naturalcycles/scrubber-lib'
const scrubberConfig : ScrubberConfig = {
fields: {
password: {
scrubber: "staticScrubber",
params: {
replacement: "***"
}
},
secret: {
scrubber: "staticScrubber",
params: {
replacement: "***"
}
}
},
throwOnError: true, // default: false,
preserveFalsy: false // default: true
};
const object = {
"created_at": "2020-06-09T07:51:58.000Z",
"password": "abcd",
"secret": "secret",
"project_id": 1,
"updated_at": "2020-06-09T07:51:58.000Z"
}
const scrubber = new Scrubber(scrubberConfig)
const scrubbedObject = scrubber.scrub(object)
console.log(scrubbedObject)
I get the expected output:
{
created_at: '2020-06-09T07:51:58.000Z',
password: '***',
secret: '***',
project_id: 1,
updated_at: '2020-06-09T07:51:58.000Z'
}
Maybe the created_at
and updated_at
fields on your object are not really strings, but Date
objects? This library will work the best if you pass strings to it.
Perhaps, I am using Sequelize ORM for my database. I will check the type of created_at.
Another suggestion would be to improve scrubber-lib
to check if the field that it is processing is an object that has a toString()
function and use that if it is available. If you are interested in making such contribution, let me know! :)
I already checked the date fields, it's literally object (Date)
{
created_at: new Date('2020-06-09T07:51:58.000Z'),
password: '***',
secret: '***',
project_id: 1,
updated_at: new Date('2020-06-09T07:51:58.000Z')
}
I guess that it will return {}
This is my code:
const { Scrubber } = require("@naturalcycles/scrubber-lib");
const scrubberConfig = {
fields: {
password: {
scrubber: "staticScrubber",
params: {
replacement: "[SCRUBBED]"
}
},
passphrase: {
scrubber: "staticScrubber",
params: {
replacement: "[SCRUBBED]"
}
},
json_credentials: {
scrubber: "staticScrubber",
params: {
replacement: "[SCRUBBED]"
}
}
},
throwOnError: true, // default: false,
preserveFalsy: false // default: true
};
const scrubber = new Scrubber(scrubberConfig);
module.exports.scrubberData = function (data) {
return scrubber.scrub(data);
};
Just checking-in, is it still an issue?
Hi @kirillgroshkov, I no longer use this package. I think it's ok to close this issue. Thank you for asking