aboutsummaryrefslogtreecommitdiff
path: root/doc/UrlFilter.md
blob: b521228d8597d6675a7eb42c7de886d85e12266d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
## FilterDomain
Filter Domains are groups of domains that can point to one or more filter
rules.

### Types
There are 4 Filter Domain types:
- AllowOnDomains - only match specified domains
- BlockOnDomains - match all but specified domains
- AllowOnAllDomains - match all domains
- BlockOnAllDomains - match no domains

### JSON
    {
        "type" : "AllowOnDomains",
        "domains" : [ "example.com", "test.example.com" ],
        "rules" : []
    }

## FilterRule
Filter rules contain information on how a request should be modified.

### Action
- Whitelist - allow this request
- Blacklist - block this request
- Redirect - redirect this request
- SetHeader - apply a list of headers

### Match Type
- "regexp"
- "contains"
- "endswith"
- if none is specified, all URLs are matched

### JSON
Allow all URLs that contain "waifu.png"
    {
        "action" : "Whitelist"
        "contains" : "waifu.png"
    }

Block specific URL
    {
        "action" : "Blacklist"
        "equals" : "example.com/annoying-ad/masquerade/waifu.png"
    }

Block all URLs that contain "banner.gif"
    {
        "action" : "Blacklist",
        "contains" : "banner.gif"
    }

Redirect URLs containing "ads/annoying-spam.gif" to "waifu.tld/waifu.gif"
    {
        "action" : "Redirect"
        "contains" : "ads/annoying-spam.gif"
        "url" : "waifu.tld/waifu.gif"
    }

Set some headers
    {
        "action" : "SetHeader"
        "headers" : [ "DNT:1" ]
    }

## QWebEngineUrlRequestInterceptor

All network requests pass through the request interceptor. It gives the
following information:

- firstPartyUrl - the page on which the request is made
- requestUrl - the url of the request
- requestMethod
- resourceType
- navigationType

And provides the following methods:

- block (bool shouldBlock) - can block the request
- redirect (const QUrl) - can redirect the requestUrl
- setHttpHeader - can set HTTP headers (such as user agent and do not track)

### Example
This is a sample request made when loading DuckDuckGo:

    firstPartyUrl=https://duckduckgo.com/
    requestUrl=https://duckduckgo.com/o1635.css

## How the filter works
When a requst comes in, the interceptor extracts the host of the request and
matches it against the list of FilterDomains.

    firstPartyHost=duckduckgo.com
    requestHost=duckduckgo.com