]> Sergey Matveev's repositories - tofuproxy.git/blob - rounds/spy.go
3b242f8cfd2b686a37d230c80553ee6508a3e558
[tofuproxy.git] / rounds / spy.go
1 /*
2 tofuproxy -- HTTP proxy with TLS certificates management
3 Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 package rounds
19
20 import (
21         "fmt"
22         "net/http"
23         "strings"
24
25         "go.stargrave.org/tofuproxy/fifos"
26 )
27
28 var spyDomains = []string{
29         "google-analytics.com",
30         "goo.gl",
31         "ads.google.com",
32         "googletagmanager.com",
33         "facebook.com",
34         "facebook.net",
35         "fbcdn.com",
36         "fbcdn.net",
37         "advertising.yandex.ru",
38         "an.yandex.ru",
39         "awaps.yandex.ru",
40         "bs.yandex.ru",
41         "informer.yandex.ru",
42         "mc.yandex.ru",
43         "metrika.yandex.ru",
44         "doubleclick.net",
45         "tns-counter.ru",
46 }
47
48 func IsSpy(host string) bool {
49         for _, spy := range spyDomains {
50                 if strings.HasSuffix(host, spy) {
51                         return true
52                 }
53         }
54         return false
55 }
56
57 func RoundDenySpy(
58         host string,
59         resp *http.Response,
60         w http.ResponseWriter,
61         req *http.Request,
62 ) (bool, error) {
63         if IsSpy(host) {
64                 http.NotFound(w, req)
65                 fifos.SinkOther <- fmt.Sprintf(
66                         "%s %s\t%d\tdeny spy",
67                         req.Method,
68                         req.URL.String(),
69                         http.StatusNotFound,
70                 )
71                 return false, nil
72         }
73         return true, nil
74 }