Bug 1353867 - Expose IsCrossOriginWhitelistedProp/AppendCrossOriginWhitelistedPropNames to DOM code. r=bzbarsky

Differential Revision: https://phabricator.services.mozilla.com/D12655

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Peter Van der Beken 2018-12-31 10:53:15 +00:00
parent a44891347b
commit 399e65fb53
3 changed files with 42 additions and 32 deletions

View File

@ -723,6 +723,15 @@ void RegisterJSStackFrame(JS::Realm* aRealm, JSStackFrameBase* aStackFrame);
void UnregisterJSStackFrame(JS::Realm* aRealm, JSStackFrameBase* aStackFrame);
void NukeJSStackFrames(JS::Realm* aRealm);
// Check whether the given jsid is a property name (string or symbol) whose
// value can be gotten cross-origin. Cross-origin gets always return undefined
// as the value, unless the Xray actually provides a different value.
bool IsCrossOriginWhitelistedProp(JSContext* cx, JS::HandleId id);
// Appends to props the jsids for property names (strings or symbols) whose
// value can be gotten cross-origin.
bool AppendCrossOriginWhitelistedPropNames(JSContext* cx,
JS::AutoIdVector& props);
} // namespace xpc
namespace mozilla {

View File

@ -10,6 +10,7 @@
#include "XrayWrapper.h"
#include "nsJSUtils.h"
#include "mozilla/ErrorResult.h"
#include "xpcpublic.h"
#include "jsapi.h"
#include "js/Symbol.h"
@ -43,6 +44,37 @@ bool IsCrossOriginWhitelistedProp(JSContext* cx, JS::HandleId id) {
IsCrossOriginWhitelistedSymbol(cx, id);
}
bool AppendCrossOriginWhitelistedPropNames(JSContext* cx,
JS::AutoIdVector& props) {
// Add "then" if it's not already in the list.
AutoIdVector thenProp(cx);
if (!thenProp.append(GetJSIDByIndex(cx, XPCJSContext::IDX_THEN))) {
return false;
}
if (!AppendUnique(cx, props, thenProp)) {
return false;
}
// Now add the three symbol-named props cross-origin objects have.
#ifdef DEBUG
for (size_t n = 0; n < props.length(); ++n) {
MOZ_ASSERT(!JSID_IS_SYMBOL(props[n]),
"Unexpected existing symbol-name prop");
}
#endif
if (!props.reserve(props.length() +
ArrayLength(sCrossOriginWhitelistedSymbolCodes))) {
return false;
}
for (auto code : sCrossOriginWhitelistedSymbolCodes) {
props.infallibleAppend(SYMBOL_TO_JSID(JS::GetWellKnownSymbol(cx, code)));
}
return true;
}
template <typename Policy>
static bool Filter(JSContext* cx, HandleObject wrapper, AutoIdVector& props) {
size_t w = 0;
@ -261,33 +293,7 @@ bool CrossOriginXrayWrapper::ownPropertyKeys(JSContext* cx,
return false;
}
// Add "then" if it's not already in the list.
AutoIdVector thenProp(cx);
if (!thenProp.append(GetJSIDByIndex(cx, XPCJSContext::IDX_THEN))) {
return false;
}
if (!AppendUnique(cx, props, thenProp)) {
return false;
}
// Now add the three symbol-named props cross-origin objects have.
#ifdef DEBUG
for (size_t n = 0; n < props.length(); ++n) {
MOZ_ASSERT(!JSID_IS_SYMBOL(props[n]),
"Unexpected existing symbol-name prop");
}
#endif
if (!props.reserve(props.length() +
ArrayLength(sCrossOriginWhitelistedSymbolCodes))) {
return false;
}
for (auto code : sCrossOriginWhitelistedSymbolCodes) {
props.infallibleAppend(SYMBOL_TO_JSID(JS::GetWellKnownSymbol(cx, code)));
}
return true;
return AppendCrossOriginWhitelistedPropNames(cx, props);
}
bool CrossOriginXrayWrapper::defineProperty(JSContext* cx,

View File

@ -85,11 +85,6 @@ class CrossOriginXrayWrapper : public SecurityXrayDOM {
JS::ObjectOpResult& result) const override;
};
// Check whether the given jsid is a property name (string or symbol) whose
// value can be gotten cross-origin. Cross-origin gets always return undefined
// as the value, unless the Xray actually provides a different value.
bool IsCrossOriginWhitelistedProp(JSContext* cx, JS::HandleId id);
} // namespace xpc
#endif /* __FilteringWrapper_h__ */