Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SuperJSON will serialize into objects that it can't deserialize #266

Closed
tmcw opened this issue Oct 17, 2023 · 0 comments · Fixed by #267
Closed

SuperJSON will serialize into objects that it can't deserialize #266

tmcw opened this issue Oct 17, 2023 · 0 comments · Fixed by #267

Comments

@tmcw
Copy link
Contributor

tmcw commented Oct 17, 2023

Testcase, run in Deno, but the same will work in Node with the packages installed and without the npm: prefixes:

/** @jsxImportSource https://esm.sh/preact */
import SuperJSON from "npm:superjson";

const value = (
  <div>
    <h1>Hello, world!</h1>
  </div>
);

console.log(SuperJSON.serialize(value));
console.log(SuperJSON.deserialize(SuperJSON.serialize(value)));

SuperJSON has a validatePath method that makes sure it isn't reaching into constructors or other dangerous properties:

https://github.com/blitz-js/superjson/blob/main/src/accessDeep.ts#L14-L24

But it doesn't have the same on the generation side, so it can't round-trip objects with these properties. A distilled testcase now that I'm looking into it:

SuperJSON.deserialize(SuperJSON.serialize({ constructor: undefined }))

This is triggered because this serializes to

{
  json: { constructor: null },
  meta: { values: { constructor: [ "undefined" ] } }
}

I don't know exactly what a better behavior would be - possibly sanitizing these properties in serialized output, or skipping them instead of throwing in deserialization?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant