Skip to content

Conversation

@Skn0tt
Copy link
Collaborator

@Skn0tt Skn0tt commented Dec 19, 2025

Closes #346

@Skn0tt Skn0tt mentioned this pull request Dec 19, 2025
@JeremyMoeglich
Copy link

This seems to introduce a regression in the following case.

import superjson from 'superjson';

const circularSet = new Set();
circularSet.add(circularSet);

const json = superjson.stringify(circularSet);
const result = superjson.parse(json);


if (result.has(result)) {
  console.log("✅ Reference preserved");
} else {
    console.error("❌ Reference broken: Set does not contain itself");
    console.log(result);
}

@JeremyMoeglich
Copy link

Also found this case that seems to regress

import superjson from 'superjson';

const sharedRegex = /\s+/;

const root = {
  a: sharedRegex,
  b: sharedRegex
};

const json = superjson.stringify(root);
const result = superjson.parse(json);

if (result.a === result.b) {
  console.log("✅ Shared reference preserved");
} else {
  console.error("❌ Shared reference lost: result.a !== result.b");
}

@Skn0tt
Copy link
Collaborator Author

Skn0tt commented Dec 19, 2025

Thanks! I found a fix for the shared regex, will take a look at the circular set after the weekend. If you find a solution i'm all ears!

@Skn0tt
Copy link
Collaborator Author

Skn0tt commented Dec 20, 2025

Managed to fix the circular set, but the diff is becoming more and more unwieldly the more I fix stuff. I'm less convinced of this approach now, but going through the motions seems to be a good way of expanding our test coverage. @JeremyMoeglich if you could try to find some more breakages, that'd be wonderful!

@JeremyMoeglich
Copy link

Found this case.

import superjson from 'superjson';

const outer = new Set();
const inner = new Set();

// outer -> inner
outer.add(inner);
// inner -> outer
inner.add(outer);

const json = superjson.stringify(outer);
const result = superjson.parse(json);

const resultInner = result.values().next().value;

if (resultInner instanceof Set && resultInner.has(result)) {
  console.log("✅ Success: Nested circular Set reference preserved");
} else {
  console.error("❌ Mismatch: Reference broken.");
}

@JeremyMoeglich
Copy link

Another case

import superjson from 'superjson';

const inner = [/a/];
const root = [inner, inner];

try {
  const json = superjson.stringify(root);
  const _ = superjson.parse(json);
} catch (e) {
  console.error(`❌ threw: ${e}`);
}

@JeremyMoeglich
Copy link

Another case:

import superjson from "superjson";

const ta = new Uint8Array(0);
const inner = [ta, ta];
const root = [inner, inner];

const s1 = superjson.stringify(root);
const roundtripped = superjson.parse(s1);
const s2 = superjson.stringify(roundtripped);

if (s1 !== s2) {
  console.error("❌ mismatch: restringified !== stringified");
  console.log(s1);
  console.log(s2);
} else {
  console.log("✅ ok: restringified === stringified");
}

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 this pull request may close these issues.

DoS via getNthKey

3 participants