-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxy-apply.PoC.js
More file actions
65 lines (55 loc) · 1.97 KB
/
Proxy-apply.PoC.js
File metadata and controls
65 lines (55 loc) · 1.97 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: BlueOak-1.0.0
import { scoring } from "./score.js";
const valueOriginal = "foobar";
const valuePolluted = "foobaz";
const fn = () => valueOriginal;
export const about = {
function: "new Proxy()",
link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy",
properties: ["'apply'"],
description: `
To create a Proxy users need to provide an object as a second argument. This
object allows specifying a myriad of traps. Usually, if a specific trap is not
specified it is not used and usual behavior is maintained. However, if any of
the traps is present on the prototype it will be used. This is also the case for
proxies created *before* the pollution happened.
Note that this does requires the proxy is on a function, it cannot make
non-function objects callable.`,
test262: new Set([
"test/built-ins/Array/prototype/lastIndexOf/calls-only-has-on-prototype-after-length-zeroed.js",
"test/built-ins/Array/prototype/indexOf/calls-only-has-on-prototype-after-length-zeroed.js",
"test/built-ins/Proxy/has/call-in-prototype-index.js",
"test/built-ins/Proxy/set/call-parameters-prototype-index.js",
"test/built-ins/Array/prototype/reverse/length-exceeding-integer-limit-with-proxy.js",
"test/built-ins/Proxy/create-target-is-not-a-constructor.js",
"test/built-ins/Proxy/apply/trap-is-null-target-is-proxy.js",
"test/built-ins/Proxy/apply/trap-is-undefined-no-property.js",
]),
};
export function prerequisite() {
const subject = new Proxy(fn, {});
const got = subject();
if (got === valueOriginal) {
return [true, null];
} else {
return [false, `got ${got}`];
}
}
export function test() {
const subject = new Proxy(fn, {});
Object.prototype.apply = () => valuePolluted;
const got = subject();
if (got === valuePolluted) {
return true;
} else {
return false;
}
}
export function cleanup() {
delete Object.prototype.apply;
}
export function score() {
return [
scoring.POLLUTE_WITH_FUNCTION,
];
}