CSP blocks editing style
Categories
(DevTools :: Inspector: Rules, defect, P2)
Tracking
(firefox72 fixed)
Tracking | Status | |
---|---|---|
firefox72 | --- | fixed |
People
(Reporter: jrmuizel, Assigned: bradwerth)
References
(Blocks 2 open bugs)
Details
(Whiteboard: [dt-q])
Attachments
(3 files, 9 obsolete files)
Updated•7 years ago
|
Comment 1•7 years ago
|
||
Comment 2•7 years ago
|
||
Reporter | ||
Comment 4•7 years ago
|
||
Comment 5•7 years ago
|
||
Comment 6•7 years ago
|
||
Assignee | ||
Comment 8•7 years ago
|
||
Comment hidden (mozreview-request) |
Comment hidden (mozreview-request) |
Assignee | ||
Comment 11•7 years ago
|
||
Assignee | ||
Comment 12•7 years ago
|
||
Assignee | ||
Comment 13•7 years ago
|
||
Comment hidden (mozreview-request) |
Comment hidden (mozreview-request) |
Comment hidden (mozreview-request) |
Comment hidden (mozreview-request) |
Assignee | ||
Comment 18•7 years ago
|
||
Assignee | ||
Updated•7 years ago
|
Comment 19•7 years ago
|
||
mozreview-review |
Updated•7 years ago
|
Comment 20•7 years ago
|
||
mozreview-review |
Comment 21•7 years ago
|
||
Comment 22•7 years ago
|
||
mozreview-review |
Comment 23•7 years ago
|
||
mozreview-review |
Comment 24•7 years ago
|
||
Comment 25•7 years ago
|
||
mozreview-review |
Assignee | ||
Comment 26•7 years ago
|
||
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Assignee | ||
Updated•6 years ago
|
Updated•6 years ago
|
Assignee | ||
Comment 28•6 years ago
|
||
Reporter | ||
Comment 29•6 years ago
|
||
Assignee | ||
Comment 30•6 years ago
|
||
Assignee | ||
Updated•6 years ago
|
Assignee | ||
Updated•6 years ago
|
Assignee | ||
Updated•6 years ago
|
Assignee | ||
Comment 31•6 years ago
|
||
Assignee | ||
Comment 32•6 years ago
|
||
Assignee | ||
Comment 33•6 years ago
|
||
Assignee | ||
Comment 34•6 years ago
|
||
Assignee | ||
Comment 35•6 years ago
|
||
Assignee | ||
Comment 36•6 years ago
|
||
Comment 37•6 years ago
|
||
Comment 38•6 years ago
|
||
Comment 39•6 years ago
|
||
Assignee | ||
Comment 41•6 years ago
|
||
Taking myself off for now. I'll re-evaluate when Bug 965637 lands.
Comment 42•5 years ago
|
||
(In reply to Brad Werth [:bradwerth] (PTO until 7/15) from comment #41)
Taking myself off for now. I'll re-evaluate when Bug 965637 lands.
Small ping since Bug 965637 has now landed :)
Also CSP starts to be enabled on various about: pages (eg https://bugzilla.mozilla.org/show_bug.cgi?id=1497197), so development on about: pages will slightly degrade.
Updated•5 years ago
|
Assignee | ||
Comment 45•5 years ago
|
||
I'm going to make another attempt at this, based off the earlier patches.
Assignee | ||
Comment 46•5 years ago
|
||
It looks like the separation of CSP from the principal doesn't fundamentally change the required approach. nsStyleUtil::CSPAllowsInlineStyle still checks aTriggeringPrincipal, but now only for the purpose of using its CSP intead of the document CSP. So it still may be possible to reach that function with an ExpandedPrincipal with no CSP specified, which will allow the editing of inline style.
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Assignee | ||
Comment 47•5 years ago
|
||
This expands Element with chrome-only setAttribute methods that give devtools
callers an ExtendedPrincipal without a nsIContentSecurityPolicy. This gives
devtools the ability to modify documents with a Content-Security-Policy.
Assignee | ||
Comment 48•5 years ago
|
||
Depends on D41313
Assignee | ||
Comment 49•5 years ago
|
||
Depends on D41319
Assignee | ||
Comment 50•5 years ago
|
||
Assignee | ||
Updated•5 years ago
|
Assignee | ||
Comment 51•5 years ago
|
||
(In reply to Kris Maglione [:kmag] from comment #25)
I think what you really want is an expanded principal that inherits from the
page principal, with the page principal's CSP, but altered to allow inline
styles. Otherwise, developers will be able to make changes via the style
editor that won't work when they apply them to their actual page CSS.
I think attachment 9084199 [details] nearly does what Kris was recommending some time ago. The difference is that the ExpandedPrincipal has NO CSP -- the patch doesn't attempt to clone and mutate the document CSP. I'm not sure if doing so would be safer/better. Kris, can you please provide feedback?
Assignee | ||
Updated•5 years ago
|
Assignee | ||
Comment 52•5 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #20)
Again, this is basically regressing part of bug 1424474. That might be OK
depending on what values come through here, but it's not obvious why it's
OK. It certainly needs documentation.
Boris, I'm hoping the new approach in attachment 9084199 [details] addresses your concerns here. Instead of applying a SystemPrincipal to the edits being done by the new devtools-only methods, it's now using an ExpandedPrincipal with no CSP. My intention is only to provide a safe bypass to the check in nsStyleUtil::CSPAllowsInlineStyle at https://searchfox.org/mozilla-central/source/layout/style/nsStyleUtil.cpp#380 without making other actions unsafe or unchecked. Is this adequate?
Comment 53•5 years ago
|
||
So what is the exact intended behavior of the new methods?
As a concrete example, if the page has a CSP that prevents loads of images from hostname "foo" and devtools is used to set the src of an <img>
to `http://foo/something", should the load happen? Using the new methods it would, right?
Also, it's not 100% clear to me whether the "use the principal's CSP if it's expanded" carveout is permanent. Christoph, do you recall what the general plan is there?
Assignee | ||
Comment 54•5 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #53)
So what is the exact intended behavior of the new methods?
We want the ability to make any change to inline style and have it stick without a CSP violation. Whether or not the change might result in a load that is disallowed per the CSP should not be affected.
As a concrete example, if the page has a CSP that prevents loads of images from hostname "foo" and devtools is used to set the src of an
<img>
to `http://foo/something", should the load happen? Using the new methods it would, right?
I don't believe that it would have this effect, since the principal only exists for the duration of the SetAttribute call, and I don't see how the load code would have access to it. But it's worth checking and I'll attempt to do that.
Comment 55•5 years ago
|
||
I don't believe that it would have this effect, since the principal only exists for the duration of the SetAttribute call,
The attribute setter passes along the principal through the load code. That's what enables extensions to do loads in web pages that would normally be blocked by the page CSP, for example.
Assignee | ||
Comment 56•5 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #55)
The attribute setter passes along the principal through the load code. That's what enables extensions to do loads in web pages that would normally be blocked by the page CSP, for example.
Since that's the case, then perhaps the fix is to create an ExtendedPrincipal that clones the document CSP and mutates the clone to add a policy that specifically allows inline style. That shouldn't allow anything else beyond the intended effect. I'll change the patches to do this, and attempt to make a test that confirms your example from comment 53 is appropriately disallowed.
Comment 57•5 years ago
|
||
We should start by writing the test and seeing whether it fails or passes with the patches as they are.
Comment 58•5 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #53)
Also, it's not 100% clear to me whether the "use the principal's CSP if it's expanded" carveout is permanent. Christoph, do you recall what the general plan is there?
The carveout is not permanent and Jonathan will try to move the CSP off the ExpandedPrincipal within Bug 1548468 for the bigger effort of making Principals threadsafe (See Bug 1443925). At the moment we don't have a clear plan where the CSP should be stored after removing it from the ExpandedPrincipal though, if you have any suggestions please leave a comment here: https://bugzilla.mozilla.org/show_bug.cgi?id=1548468#c1. That reminds me that I should follow up on that.
Comment 59•5 years ago
|
||
Overall, the problem described here is very similar to the problem described within Bug 1228985. I think we should try to find a more generic solution. Can we tag everything created by devtools somehow and then simply don't apply any CSP to it?
Comment 60•5 years ago
|
||
Can we tag everything created by devtools somehow and then simply don't apply any CSP to it?
That's more or less what this patch does, no? In the sense that we can "tag" by using an expanded principal as the principal involved...
Comment 61•5 years ago
|
||
Comment on attachment 9084199 [details]
Bug 1391994 Part 1: Add new methods to Element to set attributes via devtools.
So I think this is fine if we're OK with bypassing CSP for all callsites that use the new APIs, but not bypassing CheckLoadURI (see bug 1424474 for why we would not want to do that).
The documentation for the new methods should clearly say that it will bypass all CSP directives, not just the ones that have to do with "inline" content.
Assignee | ||
Comment 62•5 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #61)
So I think this is fine if we're OK with bypassing CSP for all callsites that use the new APIs, but not bypassing CheckLoadURI (see bug 1424474 for why we would not want to do that).
I've uploaded an updated set of patches that explicitly clone and mutate the existing document CSP to add "style-src 'unsafe-inline'", which I hope will prevent any unwanted bypassing of the CSP. I have not added a test that verifies a CheckLoadURI violation, but I did manually check the Steps to Reproduce on Bug 1424474 to confirm that the inline source change is still forbidden with these patches.
Assignee | ||
Updated•5 years ago
|
Assignee | ||
Comment 63•5 years ago
|
||
Comment 64•5 years ago
|
||
which I hope will prevent any unwanted bypassing of the CSP
I would really like us to think through which CSP bypasses are or are not wanted here, please. If we just want to allow inline styles and nothing else, that's OK, but I'd like it to be an informed decision, ideally, so we don't have people coming by later and saying "I changed the image url in devtools but it did not load; why not?" My personal take on it is that devtools-triggered changes should probably NOT be subject to page CSP, just like extensions that modify the page are not, but won't claim to know what devtools users expect to happen.
Comment 65•5 years ago
|
||
I'd probably agree with Boris: if the developer tools don't do what developers expect to happen, they might come to perceive the tools as only half useful, aka 'unreliable' from their point of view. I think we should assume that developers know what they're doing; they should be responsible themselves if they mess up, shouldn't need hand-holding?
Assignee | ||
Comment 66•5 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #64)
I would really like us to think through which CSP bypasses are or are not wanted here, please. If we just want to allow inline styles and nothing else, that's OK, but I'd like it to be an informed decision, ideally, so we don't have people coming by later and saying "I changed the image url in devtools but it did not load; why not?" My personal take on it is that devtools-triggered changes should probably NOT be subject to page CSP, just like extensions that modify the page are not, but won't claim to know what devtools users expect to happen.
Sure. The current version of the patch makes the additional privileges explicit and I hope easy to add to, but you're right that we should also have a clear goal in mind.
Harald, would you please respond with your vision on how permissive we want Devtools to be on pages with a CSP? For example, do we want the user to be able to make changes interactively that would not be allowed if the changes to the page were permanent (presuming the CSP does not also change)?
For reference, here's the devtools csp meta bug: Bug 1479015
Comment 67•5 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #64)
I would really like us to think through which CSP bypasses are or are not wanted here, please.
I'm attempting to address this point in this document: https://docs.google.com/document/d/1eP3sDsn3hG1lSRwztIagXPG5neITr0uDcSVvVaYAYYs/edit#
Please take a look and let me know of any questions.
Comment 68•5 years ago
|
||
Sorry for the lag here....
I understand that we want to bypass style-src for things devtools does. The question is what other things devtools wants to bypass and in which cases.
Comment 69•5 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #68)
The question is what other things devtools wants to bypass and in which cases.
Nothing else in DevTools injects things in the page in a way that gets blocked by CSP. Bypassing CSP for editing element styles and adding stylesheets is what we need first and foremost.
So I was going to reply that we do not want to bypass anything else.
I just stumbled upon bug 1439390 however. This one is about the "edit & resend" feature of the network panel being blocked (by connect-src I think). So this would be the only other use case I am aware of.
Comment 70•5 years ago
|
||
Nothing else in DevTools injects things in the page in a way that gets blocked by CSP.
OK. So if the user uses devtools to edit, say, the src of an image, does that not get blocked by CSP? Or does it get blocked but we want it to get blocked?
What about editing non-inline url-valued CSS properties?
What about executing manual fetch()
or XHR via the console?
Comment 71•5 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #70)
OK. So if the user uses devtools to edit, say, the src of an image, does that not get blocked by CSP? Or does it get blocked but we want it to get blocked?
It does get blocked, and we do want it to get blocked. This is also what Chrome does, and I don't think is a compelling enough use case to warrant lowering security for devtools.
What about editing non-inline url-valued CSS properties?
Same thing here, if the editing leads to loading external resources that would normally be blocked, then those should remain blocked.
What about executing manual
fetch()
or XHR via the console?
And same here, if CSP policies on the current page block this, then they should remain blocked in the console too.
The idea again is that we do not want to force unnecessary changes on the CSP engine that would only allow a few minor use cases in devtools. The major ones are about editing CSS in a simple way (as described in the doc in comment 67).
Assignee | ||
Updated•5 years ago
|
Updated•5 years ago
|
Assignee | ||
Comment 72•5 years ago
|
||
I believe I have updated the patches to match all reviewer feedback.
Assignee | ||
Comment 73•5 years ago
|
||
Comment 74•5 years ago
|
||
Comment 75•5 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/f225d8e16072
https://hg.mozilla.org/mozilla-central/rev/fa4bb19a3d19
https://hg.mozilla.org/mozilla-central/rev/70d2c0d4a3e8
Description
•