Closed Bug 986107 Opened 10 years ago Closed 10 years ago

Make new sandboxes inherit the metadata of the creating sandbox by default

Categories

(DevTools :: Debugger, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 31

People

(Reporter: mossop, Assigned: mossop)

References

Details

Attachments

(1 file, 1 obsolete file)

Bug 898559 added the notion of metadata to tag a sandbox for the add-on debugger but it requires add-ons to set it correctly when creating custom sandboxes. This patch makes the sandbox use the same metadata as the sandbox that is creating it by default.
Assignee: nobody → dtownsend+bugmail
Blocks: 986108
Attached patch patch rev 1 (obsolete) — Splinter Review
Comment on attachment 8395005 [details] [diff] [review]
patch rev 1

Failry straightforward I think but I don't know my way around xpconnect so I mostly cribbed from other places. This just tries to get the global from the JS context and then get its metadata and use that in the event that there was no metadata passed in.
Attachment #8395005 - Flags: review?(bobbyholley)
Comment on attachment 8395005 [details] [diff] [review]
patch rev 1

Review of attachment 8395005 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/xpconnect/src/Sandbox.cpp
@@ +1574,5 @@
>      if (NS_FAILED(AssembleSandboxMemoryReporterName(cx, options.sandboxName)))
>          return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
>  
> +    if (options.metadata.isNullOrUndefined())
> +        xpc::GetContextMetadata(cx, &options.metadata);

This should just be:

if (options.metadata.isNullOrUndefined()) {
  // If the caller is running in a sandbox, inherit.
  RootedObject callerGlobal(cx, CurrentGlobalOrNull(cx));
  if (IsSandbox(callerGlobal)) {
    rv = GetSandboxMetadata(cx, callerGlobal, &options.metadata);
    if (NS_WARN_IF(NS_FAILED(rv))
      return rv;
  }
}

Or somesuch.

@@ +1834,5 @@
> +
> +    targetObject = JS_GetGlobalForObject(cx, targetObject);
> +
> +    RootedObject sandbox(cx, targetObject);
> +    return xpc::GetSandboxMetadata(cx, sandbox, rval);

How do we know that the global here is a sandbox at all? GetSandboxMetadata isn't safe to call on non-sandbox globals.

::: js/xpconnect/tests/unit/test_sandbox_metadata.js
@@ +43,5 @@
>    do_check_eq(thrown, true);
> +
> +  let systemPrincipal = Components.classes['@mozilla.org/systemprincipal;1']
> +                                  .createInstance(Components.interfaces.nsIPrincipal);
> +  sandbox = Components.utils.Sandbox(systemPrincipal, {

You can just pass |this| here, which is a system-principaled global (BackstagePass) instead of explicitly grabbing the system principal.
Attachment #8395005 - Flags: review?(bobbyholley) → review-
Attached patch patch rev 2Splinter Review
Ah yes, that's much simpler
Attachment #8395005 - Attachment is obsolete: true
Attachment #8395125 - Flags: review?(bobbyholley)
Attachment #8395125 - Flags: review?(bobbyholley) → review+
https://hg.mozilla.org/mozilla-central/rev/099f98a960a9
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 31
QA Whiteboard: [qa-]
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: