-
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 filter for DNR modifyHeaders #439
Comments
or allow both and use |
Updated the post with several use cases; Implemented the suggestion of @tophf and added |
Just wanted to mention that we would also like to see this implemented. Currently, there's no easy way to modify headers and this is often required. The most important use case for us is modifying cookies, i.e. changing max time, samesite, etc. In TPAC minutes it was mentioned by @zombie that regular expressions is not the right tool, and while I agree that it's not ideally suited for the job, I don't know any other declarative alternative for modifying a string value. One can argue that headers often have a dictionary structure internally, but even in this case you'll need something like a regular expression to make the change to any dictionary value. |
FYI: Safari and Firefox are likely going to use a regular expression engine similar to the JS implementation, whereas Chrome will use RE2. Safari will intentionally not restrict the regex syntax to the regexFilter as in #344. |
Hello, this is next up on my plate. As referenced in issue 460, we may consider adding regex filters for response header values inside the HeaderCondition. This means that regexFilter inside ModifyHeaderInfo may be redundant, but could still be useful towards compressing multiple rules into one. I think the use cases highlighted in @carlosjeurissen 's comment that requires the regexFilter in ModifyHeaderInfo are the second and third ones. Exploratory specCurrently, DNR uses RE2 as the regex syntax for regex based url filters. For now, I propose that regex filters for headers will still use RE2 for consistency. Note: valueFilter is omitted here since it is already defined in HeaderInfo
Perhaps This is just an exploratory spec based on the current regex capabilities of RE2 and DNR, but early feedback is welcome. I hope this will fulfill the use cases highlighted but do let me know if I'm missing anything. Thanks, |
Problem
Currently conditionally modifying headers is generally only possible with
webRequest
. This proposal is there to make surednr
can replace as manywebRequest
usecases.The proposal would fix: https://crbug.com/1254637 and address some of the use cases described in #169
Proposal
The proposal is to add a
regexFilter
property toModifyHeaderInfo
which only apply the operation if and only if the regex matches.In addition, a
valueFilter
could be introduced to do a simple string match for performance reasons. As proposed by @tophf, bothvalueFliter
andregexFilter
could be specified, in which casevalueFilter
is tested first. If it fails, no regexMatch is required thus improving performance.Since some operations require a global match (see use case 2). So we need a way to specify them. Something like this could work:
Use case 1,
Set-Cookie
SameSite flagSee https://bugs.chromium.org/p/chromium/issues/detail?id=1254637
Set SameSite flag of
Set-Cookie
header to 'None' if it originally was 'Lax' or 'Strict'.Blocking WebRequest
DNR proposal
Use case 2, CSP changes, set directive value
Change img-src value of the 'Content-Security-Policy' header.
Keep in mind this does not remove existing
img-src
properties. It will simply inject another in front. The old one will be ignored by the browser as this is how CSP is designed. For removing an existing directive value, see use case 3.It does however handle multiple CSP set in the same header using a comma. This will require the global search regex flag.
Example CSP is:
default-src 'self'; img-src 'none'; frame-src 'none', default-src 'none'; frame-src 'self', script-src 'none'; default-src 'none'
Blocking WebRequest
DNR proposal
Use case 3, CSP changes, remove directive
Change img-src value of the 'Content-Security-Policy' header.
Blocking WebRequest
DNR proposal
The text was updated successfully, but these errors were encountered: