
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
json-masker
Advanced tools
A library for masking field values in JSON. Useful when there is a need to log JSON which potentially contains sensitive data such as PII.
$ npm install json-masker
const masker = require('json-masker');
const maskerOptions = {/*...*/};
const mask = masker(maskerOptions);
const maskedJson = mask({ /* ... */ });
Logging incoming HTTP requests:
// ...
app.post('/customers', (req, res) => {
logger.debug(mask(req.body));
// ...
});
json-masker can be configured via options object passed into factory function. Possible parameters are:
whitelist
- a field whitelist. The values of whitelisted fields will not be masked. See Whitelist section for whitelist format documentation. Default: emptywhitelists
- a collection of field whitelists. Used if whitelist
option is not present, otherwise is ignored. Allows to define multiple logicaly-split whitelists. Is only for user convenience. Internally, the collection of whitelists is merged into one anyway. Default: emptyenabled
- a boolean flag that toggles masking functionality. If set to false
, none of the fields will be masked. Might be useful for debug purposes. Default: true
A whitelist can be defined as:
['field1', 'field2']
'field1, field2'
. Whitespaces between values are optional and ignored.A field in a whitelist can be difined by:
myField
$.myFieldParent.myField
. For more details see json-path documentationconst mask = masker({
whitelist: [
/* by field name: */
'field1',
'field2',
/* by json-path: */
'$.myArray[1].someField',
'$..path.to.a.field'
],
enabled: false
});
const mask = masker({
// as a string of comma separated values
whitelist: 'field1, field2, $..myField'
});
const mask = masker({
// multiple logical whitelists
whitelists: [
'content-type, content-length, user-agent'
'country, state, province'
]
});
Example of input:
{
"firstName": "Noëlla",
"lastName": "Maïté",
"age": 26,
"gender": "Female",
"contacts": {
"email": "cbentson7@nbcnews.com",
"phone": "62-(819)562-8538",
"address": "12 Northview Way"
},
"employments": [
{
"companyName": "Reynolds-Denesik",
"startDate": "12/7/2016",
"salary": "$150"
}
],
"ipAddress": "107.196.186.197"
}
Output:
{
"firstName": "Xxxxxx",
"lastName": "Xxxxx",
"age": "**",
"gender": "Xxxxxx",
"contacts": {
"email": "xxxxxxxx*@xxxxxxx.xxx",
"phone": "**-(***)***-****",
"address": "** Xxxxxxxxx Xxx"
},
"employments": [
{
"companyName": "Xxxxxxxx-Xxxxxxx",
"startDate": "**/*/****",
"salary": "$***"
}
],
"ipAddress": "***.***.***.***"
}
*
X
x
*
(e.g. 125
becomes "***"
or 3.95
becomes "*.**"
)FAQs
A library for masking field values in JSON
The npm package json-masker receives a total of 117 weekly downloads. As such, json-masker popularity was classified as not popular.
We found that json-masker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.