Skip to content

Commit 18a4d58

Browse files
author
Phillip Clark
authored
Merge pull request #42 from flitbit/packaging-rollup
Vulnerability fix and packaging rollup
2 parents 456a172 + 7af30ca commit 18a4d58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+10884
-26823
lines changed

.circleci/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
version: 2.1
22
executors:
3-
node-12:
3+
node-14:
44
docker:
5-
- image: circleci/node:12
5+
- image: circleci/node:14
66

77
commands:
88
npm-ci:
9-
description: "standard npm-based ci workflow"
9+
description: 'standard npm-based ci workflow'
1010
steps:
1111
- checkout
1212
- run:
@@ -42,7 +42,7 @@ commands:
4242
jobs:
4343
build-pre:
4444
working_directory: ~/repo
45-
executor: node-12
45+
executor: node-14
4646
steps:
4747
- npm-ci
4848
- run:
@@ -57,7 +57,7 @@ jobs:
5757
5858
build-release:
5959
working_directory: ~/repo
60-
executor: node-12
60+
executor: node-14
6161
steps:
6262
- npm-ci
6363
- run:

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/**/*.js
22
dist/
3+
examples/

.eslintrc.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
{
22
"env": {
33
"browser": false,
4-
"es6": true,
5-
"node": true
4+
"es2020": true,
5+
"node": true,
6+
"mocha": true
67
},
78
"parser": "@typescript-eslint/parser",
89
"parserOptions": {
910
"project": "./tsconfig.json",
1011
"sourceType": "module"
1112
},
12-
"plugins": [
13-
"@typescript-eslint"
14-
],
13+
"plugins": ["@typescript-eslint", "mocha"],
1514
"extends": [
1615
"eslint:recommended",
1716
"plugin:@typescript-eslint/eslint-recommended",
1817
"plugin:@typescript-eslint/recommended",
1918
"plugin:prettier/recommended"
2019
],
2120
"rules": {}
22-
}
21+
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2011-2018 Phillip Clark
1+
Copyright (c) 2011-2021 Phillip Clark
22

33
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:
44

README.md

Lines changed: 95 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,25 @@ Supports [Relative JSON Pointers](https://tools.ietf.org/id/draft-handrews-relat
88

99
## Background
1010

11-
I wrote this a few years back when I was unable to find a _complete implementation_ of [RFC 6901](https://tools.ietf.org/html/rfc6901). It turns out that I now use the hell out of it.
12-
13-
## Security Vulnerability prior to v2.1.0
14-
15-
There is a security vulnerability in versions prior to v2.1.0 in which an unscrupulous actor may execute arbitrary code. If your code sends un-sanitized user input to `json-ptr`'s `.get()` method, your project is vulnerable to this injection-style vulnerability.
16-
17-
If your code is vulnerable, you should upgrade immediately, and also, stop sending un-sanitized user input to `json-ptr`.
18-
19-
## Breaking Changes at v1.3.0
20-
21-
As was rightly pointed out in [this issue](https://github.com/flitbit/json-ptr/issues/24), I should have rolled the major version at `v1.3.0` instead of the minor version due to [breaking changes to the API](#user-content-where-did-the-global-functions-go). Not the worst blunder I've made, but my apologies all the same. Since the ship has sailed, I'm boosting the visibility of these breaking changes.
11+
I wrote this a few years back when I was unable to find a _complete implementation_ of [RFC 6901](https://tools.ietf.org/html/rfc6901). It turns out that I now use the hell out of it. I hope you also find it useful.
2212

2313
## Install
2414

2515
```bash
2616
npm install json-ptr
2717
```
2818

19+
## Release Bundles
20+
21+
As of v3.0.0, we provide CJS, ESM, and UMD builds under the `dist/` folder when you install the package from NPM, we also have all appropriate references in our `package.json` file, so your code should just work. If you need a CDN reference to `json-ptr`, try [UNPKG](https://unpkg.com/), which picks up our releases automatically.
22+
2923
## Use
3024

31-
### [nodejs](https://nodejs.org/en/)
25+
Both CJS and ESM are supported.
26+
27+
```javascript
28+
const { JsonPointer } = require('json-ptr');
29+
```
3230

3331
```javascript
3432
import { JsonPointer } from 'json-ptr';
@@ -65,7 +63,7 @@ const versions: Record<SupportedVersion, PrimaryGuestNamePointers> = {
6563
name: JsonPointer.create('/primary/primaryGuest/name'),
6664
surname: JsonPointer.create('/primary/primaryGuest/surname'),
6765
honorific: JsonPointer.create('/primary/primaryGuest/honorific'),
68-
}
66+
},
6967
};
7068

7169
interface Reservation extends Record<string, unknown> {
@@ -94,21 +92,25 @@ function primaryGuestName(reservation: Reservation): string {
9492

9593
// The original layout of a reservation (only the parts relevant to our example)
9694
const reservationV1: Reservation = {
97-
guests: [{
98-
name: 'Wilbur',
99-
surname: 'Finkle',
100-
honorific: 'Mr.'
101-
}, {
102-
name: 'Wanda',
103-
surname: 'Finkle',
104-
honorific: 'Mrs.'
105-
}, {
106-
name: 'Wilma',
107-
surname: 'Finkle',
108-
honorific: 'Miss',
109-
child: true,
110-
age: 12
111-
}]
95+
guests: [
96+
{
97+
name: 'Wilbur',
98+
surname: 'Finkle',
99+
honorific: 'Mr.',
100+
},
101+
{
102+
name: 'Wanda',
103+
surname: 'Finkle',
104+
honorific: 'Mrs.',
105+
},
106+
{
107+
name: 'Wilma',
108+
surname: 'Finkle',
109+
honorific: 'Miss',
110+
child: true,
111+
age: 12,
112+
},
113+
],
112114
// ...
113115
};
114116

@@ -119,36 +121,48 @@ const reservationV1_1: Reservation = {
119121
primaryGuest: {
120122
name: 'Wilbur',
121123
surname: 'Finkle',
122-
honorific: 'Mr.'
124+
honorific: 'Mr.',
123125
},
124-
additionalGuests: [{
125-
name: 'Wanda',
126-
surname: 'Finkle',
127-
honorific: 'Mrs.'
128-
}, {
129-
name: 'Wilma',
130-
surname: 'Finkle',
131-
honorific: 'Miss',
132-
child: true,
133-
age: 12
134-
}]
126+
additionalGuests: [
127+
{
128+
name: 'Wanda',
129+
surname: 'Finkle',
130+
honorific: 'Mrs.',
131+
},
132+
{
133+
name: 'Wilma',
134+
surname: 'Finkle',
135+
honorific: 'Miss',
136+
child: true,
137+
age: 12,
138+
},
139+
],
135140
// ...
136-
}
141+
},
137142
// ...
138143
};
139144

140145
console.log(primaryGuestName(reservationV1));
141146
console.log(primaryGuestName(reservationV1_1));
142-
143147
```
144148

149+
## Security Vulnerabilities (Resolved)
150+
151+
- **prior to v3.0.0** there was a security vulnerability which allowed a developer to perform prototype pollution by sending malformed path segments to `json-ptr`. If you were one of these developers, you should upgrade to v3.0.0 immediately, and stop using `json-ptr` to pollute an object's prototype. If you feel you have a legitimate reason to do so, please use another method and leave `json-ptr` out of it. Such behavior has been disallowed since it can easily be done using plain ol javascript by those determined to violate common best practice.
152+
153+
- **prior to v2.1.0** there was a security vulnerability which allowed an unscrupulous actor to execute arbitrary code if developers failed to sanitize user input before sending it to `json-ptr`. If your code does not sanitize user input before sending it to `json-ptr`, your project is vulnerable and you should upgrade to v3.0.0 immediately. And while your at it, start sanitized user input before sending it to any library!
154+
155+
## Breaking Changes at v1.3.0
156+
157+
As was rightly pointed out in [this issue](https://github.com/flitbit/json-ptr/issues/24), I should have rolled the major version at `v1.3.0` instead of the minor version due to [breaking changes to the API](#user-content-where-did-the-global-functions-go). Not the worst blunder I've made, but my apologies all the same. Since the ship has sailed, I'm boosting the visibility of these breaking changes.
158+
145159
### Where did the Global Functions Go?
146160

147161
In version `v1.3.0` of the library, global functions were moved to static functions of the `JsonPointer` class. There should be no difference in arguments or behavior. If you were previously importing the global functions it is a small change to destructure them and have compatible code.
148162

149-
| Global Fn | Static Fn | Documentation |
150-
|---|---|---|
151-
| `create()`| `JsonPointer.create()` | [Factory function that creates a `JsonPointer`](http://flitbit.github.io/json-ptr/classes/_src_pointer_.jsonpointer.html#create) |
163+
| Global Fn | Static Fn | Documentation |
164+
| ------------------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
165+
| `create()` | `JsonPointer.create()` | [Factory function that creates a `JsonPointer`](http://flitbit.github.io/json-ptr/classes/_src_pointer_.jsonpointer.html#create) |
152166
| `decode()` | `JsonPointer.decode()` | [Decodes the specified pointer into path segments.](http://flitbit.github.io/json-ptr/classes/_src_pointer_.jsonpointer.html#decode) |
153167
| `flatten()` | `JsonPointer.flatten()` | [DEvaluates the target's object graph, returning a Record&lt;Pointer, unknown> populated with pointers and the corresponding values from the graph..](http://flitbit.github.io/json-ptr/classes/_src_pointer_.jsonpointer.html#flatten) |
154168
| `get()` | `JsonPointer.get()` | [Gets the target object's value at the pointer's location.](http://flitbit.github.io/json-ptr/classes/_src_pointer_.jsonpointer.html#get) |
@@ -241,54 +255,63 @@ It is important to recognize in the performance results that _compiled_ options
241255

242256
## Releases
243257

258+
- 2021-10-26 — **3.0.0** **Potential Security Vulnerability Patched**
259+
- When setting a value on an object graph, a developer could purposely use `json-ptr` to pollute an object's prototype by passing invalid path segments to the set/unset operations. This behavior has been disallowed.
244260
- 2021-05-14 — **2.2.0** _Added Handling for Relative JSON Pointers_
245261
- [Example usage](https://github.com/flitbit/json-ptr/blob/487182100a08f4ddc7713e42ec063bbd5ce2c34c/examples/relative.js)
246262
- 2021-05-12 — **2.1.1** _Bug fix for [#36](https://github.com/flitbit/json-ptr/issues/36)_
247263
- @CarolynWebster reported an unintentional behavior change starting at v1.3.0. An operation involving a pointer/path that crossed a null value in the object graph resulted in an exception. In versions prior to v1.3.0 it returned `undefined` as intended. The original behavior has been restored.
248264
- 2021-05-12 — **2.1.0** _Bug fixes for [#28](https://github.com/flitbit/json-ptr/issues/28) and [#30](https://github.com/flitbit/json-ptr/issues/30); **Security Vulnerability Patched**_
249-
- When compiling the accessors for quickly points in an object graph, the `.get()` method was not properly delimiting single quotes. This error caused the get operation to throw an exception in during normal usage. Worse, in cases where malicious user input was sent directly to `json-ptr`, the failure to delimit single quotes allowed the execution of arbitrary code (an injection attack). The first of these issues was reported in #28 by @mprast, the second (vulnerability) by @zpbrent. Thanks also to @elimumford for the actual code used for the fix.
265+
266+
- When compiling the accessors for quickly accessing points in an object graph, the `.get()` method was not properly delimiting single quotes. This error caused the get operation to throw an exception in during normal usage. Worse, in cases where malicious user input was sent directly to `json-ptr`, the failure to delimit single quotes allowed the execution of arbitrary code (an injection attack). The first of these issues was reported in #28 by @mprast, the second (vulnerability) by @zpbrent. Thanks also to @elimumford for the actual code used for the fix.
250267

251268
- If your code sent un-sanitized user input to the `.get()` method of `json-ptr`, your project was susceptible to this security vulnerability!
252-
269+
253270
- 2020-10-21 — **2.0.0** _*Breaking Change*_
254271
- Prototype pollution using this library is now disallowed and will throw an error. I've been looking into the origin of this issue and it seems to have been disclosed by mohan on [huntr.dev](https://www.huntr.dev/bounties/1-npm-json-ptr/). I received [a PR from](https://github.com/flitbit/json-ptr/pull/26) [@luci-m-666](https://github.com/luci-m-666), but found [another PR](https://github.com/418sec/json-ptr/pull/1) by [@alromh87](https://github.com/alromh87) that looks like the origin of the solution. Don't know who to thank, but thanks all -- somebody is due a bounty.
255272
- Just in case somebody was relying on `json-ptr` to support pointers across the prototype, I'm rolling the major version number because you're now broken.
256273

257274
> BEWARE of [Breaking Changes at v1.3.0!](#user-content-where-did-the-global-functions-go)
258275
259-
- 2020-07-20 — **1.3.2**
260-
- Added missing `tslib` dependency.
261-
- Documented [where the global functions are now located; moving them broke compatibility at v1.3.0](#user-content-where-did-the-global-functions-go).
276+
- 2020-07-20 — **1.3.2**
277+
278+
- Added missing `tslib` dependency.
279+
- Documented [where the global functions are now located; moving them broke compatibility at v1.3.0](#user-content-where-did-the-global-functions-go).
280+
281+
- 2020-07-10 — **1.3.0** **BREAKING CHANGES**
282+
283+
- **BREAKING CHANGE:** Global functions are now static functions on the `JsonPointer` type. See [_Where did the Global Functions Go?_](#user-content-where-did-the-global-functions-go)
284+
- Merged new `.unset()` function contributed by @chrishalbert, updated dependencies.
285+
- Migrated to typescript and retooled build/test/deploy pipeline. Definitely typed.
286+
- 100% test coverage which illuminated some idiosyncrasies; maybe we killed unobserved bugs, nobody knows.
287+
288+
- 2019-09-14 — **1.2.0**
289+
290+
- Merged new `.concat` function contributed by @vuwuv, updated dependencies.
291+
292+
- 2019-03-10 — **1.1.2**
262293

294+
- Updated packages to remove critical security concern among dev dependencies'
263295

264-
- 2020-07-10 — **1.3.0** **BREAKING CHANGES**
265-
- **BREAKING CHANGE:** Global functions are now static functions on the `JsonPointer` type. See [_Where did the Global Functions Go?_](#user-content-where-did-the-global-functions-go)
266-
- Merged new `.unset()` function contributed by @chrishalbert, updated dependencies.
267-
- Migrated to typescript and retooled build/test/deploy pipeline. Definitely typed.
268-
- 100% test coverage which illuminated some idiosyncrasies; maybe we killed unobserved bugs, nobody knows.
296+
- 2016-07-26 — **1.0.1**
269297

270-
- 2019-09-14 — **1.2.0**
271-
- Merged new `.concat` function contributed by @vuwuv, updated dependencies.
298+
- Fixed a problem with the Babel configuration
272299

273-
- 2019-03-10 — **1.1.2**
274-
- Updated packages to remove critical security concern among dev dependencies'
300+
- 2016-01-12 — **1.0.0**
275301

276-
- 2016-07-26 — **1.0.1**
277-
- Fixed a problem with the Babel configuration
302+
- Rolled major version to 1 to reflect breaking change in `.list(obj, fragmentId)`.
278303

279-
- 2016-01-12 — **1.0.0**
280-
- Rolled major version to 1 to reflect breaking change in `.list(obj, fragmentId)`.
304+
- 2016-01-02 — **0.3.0**
281305

282-
- 2016-01-02 — **0.3.0**
283-
- Retooled for node 4+
284-
- Better compiled pointers
285-
- Unrolled recursive `.list` function
286-
- Added `.map` function
287-
- Fully linted
288-
- Lots more tests and examples.
289-
- Documented many previously undocumented features.
306+
- Retooled for node 4+
307+
- Better compiled pointers
308+
- Unrolled recursive `.list` function
309+
- Added `.map` function
310+
- Fully linted
311+
- Lots more tests and examples.
312+
- Documented many previously undocumented features.
290313

291-
- 2014-10-21 — **0.2.0** Added #list function to enumerate all properties in a graph, producing fragmentId/value pairs.
314+
- 2014-10-21 — **0.2.0** Added #list function to enumerate all properties in a graph, producing fragmentId/value pairs.
292315

293316
## License
294317

__tests__/.eslintrc.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

docs/.nojekyll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.

0 commit comments

Comments
 (0)