Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: flightcontrolhq/superjson
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0
Choose a base ref
...
head repository: flightcontrolhq/superjson
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.1.0
Choose a head ref
  • 6 commits
  • 5 files changed
  • 5 contributors

Commits on Oct 22, 2023

  1. Fix code typo in README.md

    flybayer authored Oct 22, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5e01a01 View commit details

Commits on Oct 23, 2023

  1. Strip constructor, prototype, and __proto__ properties in the seriali…

    …ze step (#267)
    
    * Strip constructor, prototype, and __proto__ properties in the serialize step
    
    * Update src/plainer.ts
    
    Co-authored-by: Simon Knott <info@simonknott.de>
    
    ---------
    
    Co-authored-by: Simon Knott <info@simonknott.de>
    tmcw and Skn0tt authored Oct 23, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    47bf57d View commit details
  2. docs: add tmcw as a contributor for bug, and code (#269)

    * docs: update README.md [skip ci]
    
    * docs: update .all-contributorsrc [skip ci]
    
    ---------
    
    Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
    allcontributors[bot] authored Oct 23, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    465daae View commit details
  3. Update package.json (#264)

    nmquebb authored Oct 23, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    734a829 View commit details
  4. docs: add kidqueb as a contributor for bug, and code (#270)

    * docs: update README.md [skip ci]
    
    * docs: update .all-contributorsrc [skip ci]
    
    ---------
    
    Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
    Co-authored-by: Simon Knott <info@simonknott.de>
    allcontributors[bot] and Skn0tt authored Oct 23, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0dbf734 View commit details
  5. v2.1.0

    Skn0tt committed Oct 23, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    Skn0tt Simon Knott
    Copy the full SHA
    e7e0f30 View commit details
Showing with 52 additions and 4 deletions.
  1. +21 −1 .all-contributorsrc
  2. +8 −2 README.md
  3. +2 −1 package.json
  4. +11 −0 src/index.test.ts
  5. +10 −0 src/plainer.ts
22 changes: 21 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -268,6 +268,25 @@
"contributions": [
"doc"
]
},
{
"login": "kidqueb",
"name": "Nick Quebbeman",
"avatar_url": "https://avatars.githubusercontent.com/u/884128?v=4",
"profile": "https://github.com/kidqueb",
"contributions": [
"doc"
]
},
{
"login": "tmcw",
"name": "Tom MacWright",
"avatar_url": "https://avatars.githubusercontent.com/u/32314?v=4",
"profile": "https://macwright.com/",
"contributions": [
"bug",
"code"
]
}
],
"badgeTemplate": "<a href=\"#contributors\"><img src=\"https://img.shields.io/badge/all_contributors-<%= contributors.length %>-orange.svg?style=flat-square\" alt=\"All Contributors\"/></a>",
@@ -277,5 +296,6 @@
"repoType": "github",
"repoHost": "https://github.com",
"skipCi": true,
"commitConvention": "angular"
"commitConvention": "angular",
"commitType": "docs"
}
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

<p align="center">
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<a href="#contributors"><img src="https://img.shields.io/badge/all_contributors-28-orange.svg?style=flat-square" alt="All Contributors"/></a>
<a href="#contributors"><img src="https://img.shields.io/badge/all_contributors-29-orange.svg?style=flat-square" alt="All Contributors"/></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
<a href="https://www.npmjs.com/package/superjson">
<img alt="npm" src="https://img.shields.io/npm/v/superjson" />
@@ -75,7 +75,9 @@ const jsonString = superjson.stringify({ date: new Date(0) });
And parse your JSON like so:

```js
const object = superjson.parse < { date: Date } > jsonString;
const object = superjson.parse<
{ date: Date }
>(jsonString);

// object === { date: new Date(0) }
```
@@ -322,6 +324,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="http://www.maxmalm.se"><img src="https://avatars.githubusercontent.com/u/430872?v=4?s=100" width="100px;" alt="Max Malm"/><br /><sub><b>Max Malm</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=benjick" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/tylercollier"><img src="https://avatars.githubusercontent.com/u/366538?v=4?s=100" width="100px;" alt="Tyler Collier"/><br /><sub><b>Tyler Collier</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=tylercollier" title="Documentation">📖</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/kidqueb"><img src="https://avatars.githubusercontent.com/u/884128?v=4?s=100" width="100px;" alt="Nick Quebbeman"/><br /><sub><b>Nick Quebbeman</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/issues?q=author%3Akidqueb" title="Bug reports">🐛</a> <a href="https://github.com/blitz-js/superjson/commits?author=kidqueb" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://macwright.com/"><img src="https://avatars.githubusercontent.com/u/32314?v=4?s=100" width="100px;" alt="Tom MacWright"/><br /><sub><b>Tom MacWright</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/issues?q=author%3Atmcw" title="Bug reports">🐛</a> <a href="https://github.com/blitz-js/superjson/commits?author=tmcw" title="Code">💻</a></td>
</tr>
</tbody>
</table>

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"version": "2.0.0",
"version": "2.1.0",
"license": "MIT",
"type": "module",
"typings": "dist/index.d.ts",
"main": "./dist/index.js",
"exports": {
".": "./dist/index.js"
},
11 changes: 11 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1054,6 +1054,17 @@ test('regression: `Object.create(null)` / object without prototype', () => {
expect(parsed.date).toBeInstanceOf(Date);
});

test.each(['__proto__', 'prototype', 'constructor'])(
'serialize prototype pollution: %s',
forbidden => {
expect(() => {
SuperJSON.serialize({
[forbidden]: 1,
});
}).toThrowError(/This is a prototype pollution risk/);
}
);

test('prototype pollution - __proto__', () => {
expect(() => {
SuperJSON.parse(
10 changes: 10 additions & 0 deletions src/plainer.ts
Original file line number Diff line number Diff line change
@@ -216,6 +216,16 @@ export const walker = (
const innerAnnotations: Record<string, Tree<TypeAnnotation>> = {};

forEach(transformed, (value, index) => {
if (
index === '__proto__' ||
index === 'constructor' ||
index === 'prototype'
) {
throw new Error(
`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`
);
}

const recursiveResult = walker(
value,
identities,