Implementing $csp modifier from uBlockOrigin#27
Implementing $csp modifier from uBlockOrigin#27gunir wants to merge 3 commits intoZenPrivacy:masterfrom
Conversation
This PR implement a missing piece $csp modifier from uBO: https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#csp Signed-off-by: Gunir <134402102+gunir@users.noreply.github.com>
Signed-off-by: Gunir <134402102+gunir@users.noreply.github.com>
WalkthroughAdds a new Content-Security-Policy modifier by introducing Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✏️ Tip: You can disable this entire section by setting Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
anfragment
left a comment
There was a problem hiding this comment.
@gunir Thanks for the PR, LGTM overall! Please see the suggested comments.
| var _ ModifyingModifier = (*CSPModifier)(nil) | ||
|
|
||
| func (m *CSPModifier) Parse(modifier string) error { | ||
| if !strings.HasPrefix(modifier, "csp=") { |
There was a problem hiding this comment.
$csp exception modifiers can exist without a value, such as this example from this filter list:
@@||lewd.ninja^$cspWe need to handle this case as well, by:
- Allowing modifiers without a value in
Parse, leavingpolicyas an empty string - In
ModifyRes, skipping modifier application whenpolicyin an empty string - In
Cancels, always canceling the other policy ifm.policy == ""; otherwise, comparing policies for full equality - Adding the modifier to
exceptionrule.go
Co-authored-by: Ansar Smagul <ansar@anfragment.net> Signed-off-by: Gunir <134402102+gunir@users.noreply.github.com>
What does this PR do?
This PR will allow Zen to use $csp from uBO: https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#csp
How did you verify your code works?
This option will inject an additional Content-Security-Policy header to the HTTP network response of the requested web page. This will make Content Security Policy more strict as designed by the specification. It will be applied to document requests only.
This special filter will not block matching resources but only apply HTTP header to pages matching it. Mixing it with other options specifying resource types like image, script or frame (subdocument) cannot happen. It can still be used with 1p (first-party), 3p (third-party) or domain options.
Because of how csp filters get implemented, they allow for some interesting applications. For example, you can block scripts only in some specific path on the page:
What are the relevant issues?
Nothing, just implement this feature to be closer to uBO's syntax