-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Add a dedicated Content Security Policy (CSP) API for web extensions #574
Comments
@rdcronin @carlosjeurissen |
Thank you for discussing my issue. My main use case is to relax CSP and not to make it more strict. Regarding technical feasibility: In regards to the question if the platform should allow relaxing CSP: |
Thank you for the proposal, @nir-walkme ! Overall, I'm supportive of providing an API for targeted CSP modification. I think there's a lot of pieces we'd need to discuss here in terms of what the API surface would look like and the implementation it may provide. A few immediate notes:
I think we'll need to iron out a lot of these details more before we move onto the API specification. I'm supportive of this in general, but unfortunately, won't have bandwidth to drive it directly. It looks like Safari is neutral on the API. @Rob--W , would you want to work with @nir-walkme to flesh out this proposal more and sponsor it? |
@nir-walkme Thanks for initiating this! There are some more open ends. What if a frame is already loaded? What would happen to the page? Also one would need to find out the frameId which is as far as I know only supported in Firefox right now. Going for a matches pattern can be a good alternative. Which is closer to existing implementations (dnr/webrequest). Actually this could also be part of the contentScript API. @rdcronin As for helping directing to implementable proposals. To cover more usecases. Could we think of an API design similar to the blocking As for dealing with multiple CSPs. I don't think we actually need this for the extension developer. We can create some high-level API which abstracts away from this. Speaking from my side as developer, I either want to add or remove values to all CSPs. In the case of adding, the browser can enforce an additional CSP. In the case of removing values from directives, it can remove values from each CSP. If a directive relies on a fallback, a copy of the fallback would be made without said values. If a complete directive should be removed, all fallback directives will be removed as well. Other directives which fallback on the same directive would be cloned from the fallback. This would also help with multiple extensions messing with the CSPs and for cases in which a website decides to update their CSP. I do not think such high level API would miss any usecases. |
I suggest adding an issue to CSP working group https://github.com/w3c/webappsec-csp/issues to collect their thoughts. |
I would like to add my 2 cents to this proposal. Working for an extension used for a DAP (digital adoption platform), I should have the same constraints as @nir-walkme.
|
Is anyone working on it at the moment ? |
@aconstancin not sure anyone is actively working on an API design let alone an implementation. I shared some thoughts here #574 (comment). You are free to contribute. As for reporting. My suggestion would be to completely disable the report-uri when extensions modify the CSPs as reports would not necessarily be the cause of the authors set CSP. Thus the |
+1 for patterns
Yes, it would be ideal to not have to care wether the CSP comes from header, meta or a mix of both! Having a new specific DNR action we could maybe do something like:
Ideally, priority 1 CSP rules should be executed at the end to make sure a lower priority rule does not override it... |
Summary of the proposal:
Provide a dedicated API for an extension to read and write the Content Security Policy (CSP) of a page. It should work consistently regardless of how the CSP is configured (HTTP Header or
<meta>
element).Motivation:
<meta>
element (and maybe there will be other methods in the future) just shows that it needs its own dedicated API.Proposed API:
browser.csp.get(frameId)
Returns a dictionary of the directives of the page’s current Content Security Policy. The page is identified by the frameId.
browser.csp.set(frameId, dictionary)
Sets the Content Security Policy for the page. The page is identified by the frameId.
Validation of dictionary:
If the dictionary contains a key which is not supported by the browser (for example:
{'example-src' : 'example.com'}
), browser.csp.set should still work but the browser will ignore that key. This key might be supported by other browsers so the action should not fail.If the dictionary contains an invalid value (for example:
{'img-src' : 'example.com ;;; example.org'}
), browser.csp.set should still work but the browser will ignore that key. This key might be supported by other browsers so the action should not fail.browser.csp.onCSPChange.addListener(eventHandler)
The event handler would be called whenever the CSP of the page changes.
Example cases: Page load, page adding a
<meta>
CSP element or another extensions changes the CSP.Usage example:
The text was updated successfully, but these errors were encountered: