gecko-dev/caps
Tom Ritter 23ba7b6fe3 Bug 1583949 - Add a check for IsEvalAllowed to the worker callpath for eval() r=ckerschb,baku
This patch does several things.  Because Workers aren't on the main thread,
many of the things done are in the name of off main thread access.

1) Changes a parameter in IsEvalAllowed from a nsIPrincipal to a bool.
   We only used the principal to determined if it was the System Principal.
   Principals aren't thread safe and can only be accessed on Main Thread, so
   if we passed a Principal in, we would be in error. Instead only pass in
   the bool which - for workers - comes from a thread-safe location.

2) Separates out the Telemetry Event Recording and sending a message to the
   console into a new function nsContentSecurityUtils::NotifyEvalUsage. (And
   creates a runnable that calls it.)

   We do this because we will need to only call this method on the main thread.

   Telemetry Event Recording has only ever been called on the Main Thread.
   While I possibly-successfully cut it over to happen Off Main Thread (OMT)
   by porting preferences to StaticPrefs, I don't know if there were other
   threading assumptions in the Telemetry Code. So it would be much safer to
   just continue recording Event Telemetry on the main thread.

   Sending a message to the console requires calling GetStringBundleService()
   which requires main thread. I didn't investigate if this could be made
   thread-safe, I just threw it onto the main thread too.

   If, in IsEvalAllowed, we are on the main thread - we call NotifyEvalUsage
   directly. If we are not, we create a runnable which will then call
   NotifyEvalUsage for us on the main thread.

3) Ports allow_eval_with_system_principal and allow_eval_in_parent_process
   from bools to RelaxedAtomicBool - because we now check these prefs OMT.

4) In RuntimeService.cpp, adds the call to IsEvalAllowed.

5) Add resource://gre/modules/workers/require.js to the allowlist of eval
   usage. This was the script that identified this gap in the first place.
   It uses eval (twice) for structural reasons (scope and line number
   massaging.)  The contents of the eval are the result of a request to a
   uri (which may be internal, like resource://). The whole point of this
   is to implement a CommonJS require() api.

   This usage of eval is safe because the only way an attacker can inject
   into it is by either controlling the response of the uri request or
   controlling (or appending to) the argument. If they can do that, they
   are able to inject script into Firefox even if we cut this usage of eval
   over to some other type of safe(r) script loader.

   Bug 1584564 tracks making sure calls to require.js are safe.

6) Adds cld-worker.js to the allowlist. Bug 1584605 is for refactoring that
   eval usage, which is decidedly non-trivial.

7) Does _not_ enforce the eval restrictions for workers. While I've gotten
   try to be green and not throw up any instances of eval-usage by workers,
   it is much safer to deploy this is Telemetry-only mode for Workers for
   a little bit to see if anything pops up from the Nightly population.

   Bug 1584602 is for enforcing the checks.

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

--HG--
extra : moz-landing-system : lando
2019-10-08 17:31:35 +00:00
..
tests Bug 1519636 - Reformat recent changes to the Google coding style r=Ehsan 2019-07-16 07:33:44 +00:00
BasePrincipal.cpp Bug 1583871 Refactor ThirdpartyUtil.cpp r=ckerschb 2019-10-02 15:10:40 +00:00
BasePrincipal.h Bug 1583871 Refactor ThirdpartyUtil.cpp r=ckerschb 2019-10-02 15:10:40 +00:00
ContentPrincipal.cpp Bug 1558915 - Use infallible nsIURI::SchemeIs in various places r=Ehsan 2019-08-07 19:49:40 +00:00
ContentPrincipal.h Bug 1560455 - rename CodebasePrincipal to ContentPrincipal. r=ckerschb 2019-07-08 16:37:45 +00:00
DomainPolicy.cpp Bug 1289211 - Rename InfallibleTArray to nsTArray in caps/ r=bzbarsky 2019-07-10 03:24:29 +00:00
DomainPolicy.h Bug 1289211 - Rename InfallibleTArray to nsTArray in caps/ r=bzbarsky 2019-07-10 03:24:29 +00:00
ExpandedPrincipal.cpp Bug 1547707 - Add in origin attributes to ExpandedPrincipal serialization. r=ckerschb 2019-06-05 11:27:16 +00:00
ExpandedPrincipal.h Bug 1547707 - Add in origin attributes to ExpandedPrincipal serialization. r=ckerschb 2019-06-05 11:27:16 +00:00
NullPrincipal.cpp Bug 1560455 - rename CodebasePrincipal to ContentPrincipal. r=ckerschb 2019-07-08 16:37:45 +00:00
NullPrincipal.h Bug 1508939 - cpp serialization r=ckerschb,mccr8,mikedeboer 2019-06-03 12:37:12 +00:00
NullPrincipalURI.cpp Bug 1556747 - Remove UUIDGenerator dependency of NullPrincipalURI.cpp r=ckerschb 2019-06-05 12:07:33 +00:00
NullPrincipalURI.h Bug 1547143 - Format the tree: Be prescriptive with the pointer style (left) r=Ehsan 2019-05-01 08:47:10 +00:00
OriginAttributes.cpp Bug 1554805 - Never set firstPartyDomain on origin attributes for moz-extension. r=rpl,Ehsan,tjr 2019-10-06 15:43:39 +00:00
OriginAttributes.h Bug 1519636 - Reformat recent changes to the Google coding style r=Ehsan 2019-08-13 07:15:25 +00:00
SystemPrincipal.cpp Bug 1508939 - cpp serialization r=ckerschb,mccr8,mikedeboer 2019-06-03 12:37:12 +00:00
SystemPrincipal.h Bug 1508939 - cpp serialization r=ckerschb,mccr8,mikedeboer 2019-06-03 12:37:12 +00:00
moz.build Bug 1508939 - cpp serialization r=ckerschb,mccr8,mikedeboer 2019-06-03 12:37:12 +00:00
nsIAddonPolicyService.idl Bug 1545822 - Clean up some whitespace in XPIDL files. r=froydnj 2019-04-21 01:47:00 +00:00
nsIDomainPolicy.idl Bug 1507540 part 1. Use more notxpcom attributes in caps/. r=mrbkap 2018-11-19 20:17:52 -05:00
nsIPrincipal.idl Bug 1583871 Refactor ThirdpartyUtil.cpp r=ckerschb 2019-10-02 15:10:40 +00:00
nsIScriptSecurityManager.idl Bug 1560455 - rename CodebasePrincipal to ContentPrincipal. r=ckerschb 2019-07-08 16:37:45 +00:00
nsJSPrincipals.cpp Bug 1576254 - Add isSystemOrAddonPrincipal to JSPrincipal and nsJSPrincipals r=luke 2019-10-04 17:37:36 +00:00
nsJSPrincipals.h Bug 1576254 - Add isSystemOrAddonPrincipal to JSPrincipal and nsJSPrincipals r=luke 2019-10-04 17:37:36 +00:00
nsScriptSecurityManager.cpp Bug 1583949 - Add a check for IsEvalAllowed to the worker callpath for eval() r=ckerschb,baku 2019-10-08 17:31:35 +00:00
nsScriptSecurityManager.h Bug 1511393 - Use c-basic-offset: 2 in Emacs mode line for C/C++ code. r=nbp 2018-12-01 04:52:05 +09:00