Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@bugsnag/safe-json-stringify
Advanced tools
Prevent defined property getters from throwing errors
@bugsnag/safe-json-stringify is a utility for safely converting JavaScript objects to JSON strings. It is designed to handle circular references and other issues that can cause JSON.stringify to throw errors.
Safe JSON Stringify
This feature allows you to safely stringify objects that contain circular references. The code sample demonstrates how to use the package to stringify an object with a circular reference without causing an error.
{"example":"const safeJsonStringify = require('@bugsnag/safe-json-stringify');\nconst obj = { name: 'Alice' };\nobj.self = obj;\nconst jsonString = safeJsonStringify(obj);\nconsole.log(jsonString);"}
circular-json is another package that handles circular references in JSON objects. It provides similar functionality to @bugsnag/safe-json-stringify by allowing you to stringify objects with circular references without throwing errors.
flatted is a package that offers a way to serialize and deserialize JavaScript objects containing circular references. It uses a different approach compared to @bugsnag/safe-json-stringify, focusing on a more compact representation of the circular references.
json-stringify-safe is a package that provides a drop-in replacement for JSON.stringify, handling circular references by replacing them with a placeholder. It is similar to @bugsnag/safe-json-stringify in its goal to prevent errors during stringification.
This is a fork of safe-json-stringify
with some opinionated changes, specifically for Bugsnag's use-case:
...
in such circumstances.npm install @bugsnag/safe-json-stringify
The API is the same as JSON.stringify
, with an additional options
object:
stringify(obj, [optional replacer], [optional spaces], [options])
options.redactedKeys
: a list of keys whose value should be replaced with the string [REDACTED]
. Keys can be strings for case insensitive matches, or regexes for partial or pattern matches. The array can contain a mixture of both.options.redactedPaths
: a list of paths where the redactedKeys
option will be applied. The format of these strings are key names separated by .
and if the property is an array, it is represented with []
. For example: events.[].metaData
.var stringify = require('@bugsnag/safe-json-stringify')
stringify({
api_key: 'd145b8e5afb56516423bc4d605e45442',
events: [
{
errorMessage: 'Failed load tickets',
errorClass: 'CheckoutError',
user: {
name: 'Jim Bug',
email: 'jim@bugsnag.com',
api_key: '245b39ebd3cd3992e85bffc81c045924'
}
}
]
}, null, 2, {
redactedKeys: [ 'api_key' ],
redactedPaths: [ 'events.[].user' ]
})
// yields the following json:
// {
// "api_key": "d145b8e5afb56516423bc4d605e45442",
// "events": [
// {
// "errorMessage": "Failed load tickets",
// "errorClass": "CheckoutError",
// "user": {
// "name": "Jim Bug",
// "email": "jim@bugsnag.com",
// "api_key": "[REDACTED]"
// }
// }
// ]
// }
The original code is licensed with MIT, and so are the modifications.
The MIT License (MIT)
Copyright (c) 2014-2018 Debitoor, Bugsnag
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Prevent defined property getters from throwing errors
The npm package @bugsnag/safe-json-stringify receives a total of 515,810 weekly downloads. As such, @bugsnag/safe-json-stringify popularity was classified as popular.
We found that @bugsnag/safe-json-stringify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 10 open source maintainers 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.