Comparing version
@@ -5,3 +5,3 @@ 'use strict'; | ||
const internals = { | ||
suspectRx: /"(?:_|\\u005f)(?:_|\\u005f)(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006f)(?:t|\\u0074)(?:o|\\u006f)(?:_|\\u005f)(?:_|\\u005f)"\s*\:/ | ||
suspectRx: /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*\:/ | ||
}; | ||
@@ -88,1 +88,12 @@ | ||
}; | ||
exports.safeParse = function (text, reviver) { | ||
try { | ||
return exports.parse(text, reviver); | ||
} | ||
catch (ignoreError) { | ||
return null; | ||
} | ||
}; |
{ | ||
"name": "bourne", | ||
"description": "JSON parse with prototype poisoning protection", | ||
"version": "1.1.2", | ||
"version": "1.3.3", | ||
"repository": "git://github.com/hapijs/bourne", | ||
"engines": { | ||
"node": ">=6.0.0" | ||
}, | ||
"main": "lib/index.js", | ||
@@ -15,11 +18,10 @@ "keywords": [ | ||
"devDependencies": { | ||
"benchmark": "^2.1.4", | ||
"code": "5.x.x", | ||
"lab": "18.x.x" | ||
"code": "4.x.x", | ||
"lab": "14.x.x" | ||
}, | ||
"scripts": { | ||
"test": "lab -a code -t 100 -L", | ||
"test-cov-html": "lab -a code -r html -o coverage.html" | ||
"test": "lab -a code -t 100 -L -l", | ||
"test-cov-html": "lab -a code -r html -o coverage.html -l" | ||
}, | ||
"license": "BSD-3-Clause" | ||
"license": "SEE LICENSE IN LICENSE.md" | ||
} |
@@ -0,1 +1,3 @@ | ||
<a href="http://hapijs.com"><img src="https://raw.githubusercontent.com/hapijs/assets/master/images/family.png" width="180px" align="right" /></a> | ||
# Bourne. JSON Bourne. | ||
@@ -5,47 +7,6 @@ | ||
## Introduction | ||
[](https://travis-ci.org/hapijs/bourne) | ||
Consider this: | ||
## License | ||
``` | ||
> const a = '{"__proto__":{ "b":5}}'; | ||
'{"__proto__":{ "b":5}}' | ||
> const b = JSON.parse(a); | ||
{ __proto__: { b: 5 } } | ||
> b.b; | ||
undefined | ||
> const c = Object.assign({}, b); | ||
{} | ||
> c.b | ||
5 | ||
``` | ||
The problem is that `JSON.parse()` retains the `__proto__` property as a plain object key. By | ||
itself, this is not a security issue. However, as soon as that object is assigned to another or | ||
iterated on and values copied, the `__proto__` property leaks and becomes the object's prototype. | ||
## API | ||
### `Bourne.parse(text, [reviver], [options])` | ||
Parses a given JSON-formatted text into an object where: | ||
- `text` - the JSON text string. | ||
- `reviver` - the `JSON.parse()` optional `reviver` argument. | ||
- `options` - optional configuration object where: | ||
- `protoAction` - optional string with one of: | ||
- `'error'` - throw a `SyntaxError` when a `__proto__` key is found. This is the default value. | ||
- `'remove'` - deletes any `__proto__` keys from the result object. | ||
- `'ignore'` - skips all validation (same as calling `JSON.parse()` directly). | ||
### `Bourne.scan(obj, [options])` | ||
Scans a given object for prototype properties where: | ||
- `obj` - the object being scanned. | ||
- `options` - optional configuration object where: | ||
- `protoAction` - optional string with one of: | ||
- `'error'` - throw a `SyntaxError` when a `__proto__` key is found. This is the default value. | ||
- `'remove'` - deletes any `__proto__` keys from the input `obj`. | ||
This version of the package requires a commercial license. You may not use, copy, or distribute it without first acquiring a commercial license from Sideway Inc. Using this software without a license is a violation of US and international law. To obtain a license, please contact [sales@sideway.com](mailto:sales@sideway.com). The open source version of this package can be found [here](https://github.com/hapijs/bourne). |
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
2
-33.33%66
13.79%4058
-25.84%2
Infinity%1
Infinity%80
-20%11
-78.43%1
Infinity%