Skip to content

Commit fe52854

Browse files
mhorowitzbigfootjon
authored andcommitted
[CVE-2020-1911] Look up HostObject computed properties on the right object in the prototype chain.
Summary: The change in the hermes repository fixes the security vulnerability CVE-2020-1911. This vulnerability only affects applications which allow evaluation of uncontrolled, untrusted JavaScript code not shipped with the app, so React Native apps will generally not be affected. This revision includes a test for the bug. The test is generic JSI code, so it is included in the hermes and react-native repositories. Changelog: [Internal] Reviewed By: tmikov Differential Revision: D23322992 fbshipit-source-id: 4e88c974afe1ad33a263f9cac03e9dc98d33649a
1 parent de05c8c commit fe52854

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

API/jsi/jsi/test/testlib.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,23 @@ TEST_P(JSITest, HostObjectTest) {
394394
.getBool());
395395
}
396396

397+
TEST_P(JSITest, HostObjectProtoTest) {
398+
class ProtoHostObject : public HostObject {
399+
Value get(Runtime& rt, const PropNameID&) override {
400+
return String::createFromAscii(rt, "phoprop");
401+
}
402+
};
403+
404+
rt.global().setProperty(
405+
rt,
406+
"pho",
407+
Object::createFromHostObject(rt, std::make_shared<ProtoHostObject>()));
408+
409+
EXPECT_EQ(
410+
eval("({__proto__: pho})[Symbol.toPrimitive]").getString(rt).utf8(rt),
411+
"phoprop");
412+
}
413+
397414
TEST_P(JSITest, ArrayTest) {
398415
eval("x = {1:2, '3':4, 5:'six', 'seven':['eight', 'nine']}");
399416

lib/VM/JSObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ CallResult<PseudoHandle<>> JSObject::getComputedWithReceiver_RJS(
11731173
} else if (desc.flags.hostObject) {
11741174
SymbolID id{};
11751175
LAZY_TO_IDENTIFIER(runtime, nameValPrimitiveHandle, id);
1176-
auto propRes = vmcast<HostObject>(selfHandle.get())->get(id);
1176+
auto propRes = vmcast<HostObject>(propObj.get())->get(id);
11771177
if (propRes == ExecutionStatus::EXCEPTION)
11781178
return ExecutionStatus::EXCEPTION;
11791179
return createPseudoHandle(*propRes);

0 commit comments

Comments
 (0)