gecko-dev/dom/security
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
..
featurepolicy Bug 1579373 - Disabled geolocation permission for crossorigin iframe by default and add tests r=baku 2019-09-09 20:00:56 +00:00
fuzztest Bug 1560455 - rename CodebasePrincipal to ContentPrincipal. r=ckerschb 2019-07-08 16:37:45 +00:00
test Bug 1585055 - Flip Pref for XTCO-NoSniff and update test to match r=ckerschb 2019-10-07 12:05:36 +00:00
CSPEvalChecker.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
CSPEvalChecker.h
FramingChecker.cpp Bug 1559414 - Rename unaudited pre-fission methods with SameProcess for future audit burndown. r=nika 2019-07-26 16:48:31 +00:00
FramingChecker.h Bug 1301529 - Remove X-Frame-Options allow-from. r=ckerschb 2019-07-24 12:23:32 +00:00
moz.build Bug 1573145: Create ContentSecurityUtils.h/cpp and move AssertAboutPageHasCSP into it. r=jkt 2019-08-14 10:15:09 +00:00
nsContentSecurityManager.cpp Bug 1573276 - Always allow localization in error pages r=johannh,peterv 2019-09-25 10:39:45 +00:00
nsContentSecurityManager.h Bug 1570681 - Move Eval testing logic from nsContentSecurityManager to nsContentSecurityUtils r=ckerschb 2019-09-18 19:36:31 +00:00
nsContentSecurityUtils.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
nsContentSecurityUtils.h Bug 1583949 - Add a check for IsEvalAllowed to the worker callpath for eval() r=ckerschb,baku 2019-10-08 17:31:35 +00:00
nsCSPContext.cpp Bug 1583932 - Remove aRequestOrigin from nsCSPContext::ShouldLoad r=ckerschb 2019-09-30 10:38:32 +00:00
nsCSPContext.h Bug 1580710: Expose functionality on the CSP Object to allow skipping the inline style checks. r=bzbarsky 2019-09-16 23:47:19 +00:00
nsCSPParser.cpp Bug 1529068 - Implementation of the navigate-to CSP directive as defined in CSP Level 3. r=ckerschb,mccr8 2019-09-10 22:33:51 +00:00
nsCSPParser.h Bug 1557793 part 2. Stop using [array] in nsIStringBundle. r=Pike 2019-06-11 15:51:51 +00:00
nsCSPService.cpp Bug 1583932 - Remove aRequestOrigin from nsCSPContext::ShouldLoad r=ckerschb 2019-09-30 10:38:32 +00:00
nsCSPService.h Bug 1583076 - Make nsCSPService::ConsultCSPForRedirect return both the AsyncOnChannelRedirect result, as well as an optional result to cancel the old channel with. r=ckerschb 2019-09-25 08:25:22 +00:00
nsCSPUtils.cpp Bug 1529068 - Implementation of the navigate-to CSP directive as defined in CSP Level 3. r=ckerschb,mccr8 2019-09-10 22:33:51 +00:00
nsCSPUtils.h Bug 1529068 - Implementation of the navigate-to CSP directive as defined in CSP Level 3. r=ckerschb,mccr8 2019-09-10 22:33:51 +00:00
nsMixedContentBlocker.cpp Bug 1585604 - Remove telemetry for mixed object subrequst counting. r=ckerschb 2019-10-02 11:17:28 +00:00
nsMixedContentBlocker.h Bug 1376309 - Allow localhost ws:// connections from secure origins. r=jkt 2019-08-07 00:19:59 +00:00
PolicyTokenizer.cpp Bug 1530369 - part 3 - do less copying in generateTokens; r=ckerschb 2019-02-25 13:58:53 -05:00
PolicyTokenizer.h Bug 1530369 - part 1 - don't needlessly write characters when skipping; r=ckerschb 2019-02-25 13:58:54 -05:00
ReferrerInfo.cpp Bug 1528697 - Add cenum referrerpolicy in ReferrerInfo.idl r=ckerschb,Gijs 2019-08-21 13:28:23 +00:00
ReferrerInfo.h Bug 1528697 - Expose ReferrerPolicy.webidl and use referrerpolicy enum r=smaug 2019-08-21 13:24:45 +00:00
SRICheck.cpp Bug 1523969 part 6 - Move method definition inline comments to new line in 'dom/'. r=nika 2019-02-25 16:05:29 -06:00
SRICheck.h
SRILogHelper.h
SRIMetadata.cpp
SRIMetadata.h