This commit does two things. Firstly it enforces eval restrictions in Workers per Bug 1584602.
We're collecting telemetry on these in Beta (and not seeing any) so we can let enforcement ride up to Beta.
Secondly, it disables enforcement checks on Release (and late Beta, as explained in the comment) until
we can gather data about what's happening in Release. This is a counterpart to Bug 1592349 for -central.
We have two separate commits because the first part of this is a change in the same code and we'd have
rebase problems if we tried to do them both separately.
This does tie enforcement to a build-time constant instead of leaving it as a pref. This doesn't make
me very happy inside, but I don't think the extra complexity is worth it...
Differential Revision: https://phabricator.services.mozilla.com/D50970
--HG--
extra : moz-landing-system : lando
Converts network.http.referer.defaultPolicy, network.http.referer.defaultPolicy.trackers, network.http.referer.defaultPolicy.pbmode, and network.http.referer.defaultPolicy.trackers.pbmode to static prefs and updates the uses of their old mirror values.
Differential Revision: https://phabricator.services.mozilla.com/D50541
--HG--
extra : moz-landing-system : lando
Converts network.http.referer.XOriginTrimmingPolicy to a static pref. Leverages do_not_use_directly and a getter to clamp the pref value.
Differential Revision: https://phabricator.services.mozilla.com/D50540
--HG--
extra : moz-landing-system : lando
Converts network.http.referer.trimmingPolicy and leverages do_not_use_directly with a getter to clamp the value.
Differential Revision: https://phabricator.services.mozilla.com/D50539
--HG--
extra : moz-landing-system : lando
Converts network.http.referer.XOriginPolicy to a static pref and leverages 'do_not_use_directly' and a getter in order to clamp the value.
Differential Revision: https://phabricator.services.mozilla.com/D50537
--HG--
extra : moz-landing-system : lando
Converts network.http.referer.referrerLengthLimit to a static pref and replaces its mirror variable.
Differential Revision: https://phabricator.services.mozilla.com/D50536
--HG--
extra : moz-landing-system : lando
Converts network.http.sendRefererHeader to a static pref. The original mirror variable was clamped between 0 and 2, so the pref has been updated with DoNotUseDirectly and a getter.
Differential Revision: https://phabricator.services.mozilla.com/D50535
--HG--
extra : moz-landing-system : lando
Converts network.http.referer.hideOnionSource to a static pref and removes its mirror variable and varcache pref definition.
Differential Revision: https://phabricator.services.mozilla.com/D50534
--HG--
extra : moz-landing-system : lando
Converts network.http.referer.spoofSource to a static pref and removes the varcache instance and mirror variable.
Differential Revision: https://phabricator.services.mozilla.com/D50533
--HG--
extra : moz-landing-system : lando
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