Skip to content

Commit

Permalink
Preventing attempt to return IDispatch that is not IHTMLElement for IE
Browse files Browse the repository at this point in the history
When returning values from JavaScript, if a variant value is an IDispatch,
but does not implement IHTMLElement, and also is not recognized as a
JavaScript array or object, avoid returning it from the script. This is
also to prevent returning things like a window or document reference, as
those items contain recursive references that cannot be properly
serialized to JSON.
  • Loading branch information
jimevans committed Jul 31, 2018
1 parent 7842db3 commit 458daaf
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cpp/iedriver/VariantUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,23 @@ int VariantUtilities::ConvertVariantToJsonValue(IElementManager* element_manager
} else {
LOG(INFO) << "Unknown type of dispatch is found in result, assuming IHTMLElement";
CComPtr<IHTMLElement> node;
variant_value.pdispVal->QueryInterface<IHTMLElement>(&node);
HRESULT hr = variant_value.pdispVal->QueryInterface<IHTMLElement>(&node);
if (FAILED(hr)) {
CComPtr<IHTMLWindow2> window_node;
hr = variant_value.pdispVal->QueryInterface<IHTMLWindow2>(&window_node);
if (SUCCEEDED(hr) && window_node) {
// TODO: We need to track window objects and return a custom JSON
// object according to the spec, but that will require a fair
// amount of refactoring.
LOG(DEBUG) << "Returning window object from JavaScript is not supported";
}

// We've already done our best to check if the object is an array or
// an object. We now know it doesn't implement IHTMLElement. We have
// no choice but to throw up our hands here.
LOG(WARN) << "Dispatch value is not recognized as a JavaScript object, array, or element reference";
return EUNEXPECTEDJSERROR;
}
ElementHandle element_wrapper;
bool element_added = element_manager->AddManagedElement(node, &element_wrapper);
Json::Value element_value(Json::objectValue);
Expand Down

0 comments on commit 458daaf

Please sign in to comment.