-
Notifications
You must be signed in to change notification settings - Fork 56
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 dictionary operations to DNR modifyHeaders #440
Comments
We discussed this at the WECG Meet-Up. Browser vendors were agreed that, in a perfect world, we would like to support something like this. However, there's two major concerns we have with this approach:
Because of these, we're unlikely to pursue this at this time. However, we agreed that CSP modification in particular may be worth exploring with other functionality (even independent of declarativeNetRequest, as CSP can also be provided through e.g. We are also all supportive of allowing something similar (though less structured) as proposed in #439. Thanks again for the proposal, @carlosjeurissen ; this was definitely a cool idea to explore. |
Problem
Currently when attempting to change headers with a dictionary structure one can only set or remove the header. For many use cases like #169 and https://crbug.com/1254637, this is problematic. This proposal is there to make sure
dnr
can replace as manywebRequest
usecases.In addition, if multiple extensions attempt to modify headers conflicts are likely to occur.
Proposal
In addition to the 'append', 'set' and 'remove' operations, we can introduce a dictionary operation with a set of key-value transformations. The
value
property will be an Array with headerDictionaryAction as such:The operations available for headerDictionaryAction are 'set', 'append', 'remove' and 'removeValue'.
Since headers using dictionaries have different syntaxes (for example,
Content-Security-Policy
,Permissions-Policy
,Set-Cookie
), this is something we have to consider.The Content-Security-Policy header can have multiple dictionaries. Which makes this especially interesting. My proposal would be to have the operations be applied to each dictionary individually. Keep in mind CSP values with multiple dictionaries are very common, but common enough we need to handle them.
Say we have a
Content-Security-Policy
header with the following value:default-src 'none'; img-src 'self'; script-src 'self'; frame-src 'self', default-src 'self'; media-src 'none', default-src 'none'; connect-src 'self'
The dictionaries are separated by commas. So we deal with three CSPs here, being:
default-src 'none'; img-src 'self'; script-src 'self'; frame-src 'none'
default-src 'self'
default-src 'none'; connect-src 'self'
With below operations:
This would result in:
default-src 'none'; img-src https://example.com/image.png; script-src 'self'; frame-src 'none'; connect-src 'none'
default-src 'self'; img-src https://example.com/image.png; connect-src 'none'
default-src 'none'; connect-src 'none'; img-src https://example.com/image.png
Note the difference between the handling of
frame-src
andmedia-src
. Since 'self' is removed fromframe-src
, we have a special situation in which no value is present. This would mean no value is present forframe-src
. To keep the CSP valid, a value of 'none' would thus be added. If the preferred result is to completely remove it one can use theremove
operator as demonstrated withmedia-src
.Which would then be merged as like such:
default-src 'none'; img-src https://example.com/image.png; script-src 'self'; frame-src 'none'; connect-src 'none', default-src 'self'; img-src https://example.com/image.png; connect-src 'none',default-src 'none'; connect-src 'none'; img-src https://example.com/image.png
The text was updated successfully, but these errors were encountered: