-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSONStringify-toJSON.PoC.js
More file actions
48 lines (40 loc) · 1.05 KB
/
JSONStringify-toJSON.PoC.js
File metadata and controls
48 lines (40 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: BlueOak-1.0.0
import { scoring } from "./score.js";
export const about = {
function: "JSON.stringify",
link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify",
properties: ["'toJSON'"],
description: `
The JSON.stringify function allows objects to specify custom serialization via
the toJSON method. Hence, by polluting this you can control how objects without
an explicit toJSON method are serialized.`,
spectrace: [
"https://tc39.es/ecma262/#sec-json.stringify",
"https://tc39.es/ecma262/#sec-serializejsonproperty",
],
};
export function prerequisite() {
const got = JSON.stringify({});
if (got === "{}") {
return [true, null];
} else {
return [false, `got ${got}`];
}
}
export function test() {
Object.prototype.toJSON = () => [];
const got = JSON.stringify({});
if (got === "[]") {
return true;
} else {
return false;
}
}
export function cleanup() {
delete Object.prototype.toJSON;
}
export function score() {
return [
scoring.POLLUTE_WITH_FUNCTION,
];
}