Skip to content

Commit 57547d1

Browse files
authored
Ban setting 'Object.prototype.__proto__' as Proxy to prevent circular referencing (#4961)
in prototype chain. This patch fixes #4941 JerryScript-DCO-1.0-Signed-off-by: Martin Negyokru [email protected]
1 parent e9da834 commit 57547d1

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

jerry-core/ecma/operations/ecma-objects.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,6 +3332,15 @@ ecma_op_ordinary_object_set_prototype_of (ecma_object_t *obj_p, /**< base object
33323332
#if JERRY_BUILTIN_PROXY
33333333
if (ECMA_OBJECT_IS_PROXY (iter_p))
33343334
{
3335+
/**
3336+
* Prevent setting 'Object.prototype.__proto__'
3337+
* to avoid circular referencing in the prototype chain.
3338+
*/
3339+
if (obj_p == ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE))
3340+
{
3341+
return ECMA_VALUE_FALSE;
3342+
}
3343+
33353344
break;
33363345
}
33373346
#endif /* JERRY_BUILTIN_PROXY */
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
try {
16+
Object.prototype.__proto__ = new Proxy({}, {});
17+
assert(false);
18+
} catch (e) {
19+
assert(e instanceof TypeError);
20+
}
21+
22+
try {
23+
__proto__.__proto__ = new Proxy({}, {});
24+
assert(false);
25+
} catch (e) {
26+
assert(e instanceof TypeError);
27+
}

0 commit comments

Comments
 (0)