-
Notifications
You must be signed in to change notification settings - Fork 922
/
Copy pathshield_exceptions.cc
75 lines (67 loc) · 2.62 KB
/
shield_exceptions.cc
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
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "brave/common/shield_exceptions.h"
#include <algorithm>
#include <map>
#include <vector>
#include "extensions/common/url_pattern.h"
#include "url/gurl.h"
namespace brave {
bool IsUAWhitelisted(const GURL& gurl) {
static std::vector<URLPattern> whitelist_patterns({
URLPattern(URLPattern::SCHEME_ALL, "https://*.adobe.com/*"),
URLPattern(URLPattern::SCHEME_ALL, "https://*.duckduckgo.com/*"),
URLPattern(URLPattern::SCHEME_ALL, "https://*.brave.com/*"),
// For Widevine
URLPattern(URLPattern::SCHEME_ALL, "https://*.netflix.com/*")
});
return std::any_of(whitelist_patterns.begin(), whitelist_patterns.end(),
[&gurl](URLPattern pattern){
return pattern.MatchesURL(gurl);
});
}
bool IsBlockedResource(const GURL& gurl) {
static std::vector<URLPattern> blocked_patterns({
URLPattern(URLPattern::SCHEME_ALL, "https://pdfjs.robwu.nl/*")
});
return std::any_of(blocked_patterns.begin(), blocked_patterns.end(),
[&gurl](URLPattern pattern){
return pattern.MatchesURL(gurl);
});
}
bool IsWhitelistedFingerprintingException(const GURL& firstPartyOrigin,
const GURL& subresourceUrl) {
static std::map<URLPattern, std::vector<URLPattern> > whitelist_patterns = {
{
URLPattern(URLPattern::SCHEME_ALL, "https://uphold.com/"),
std::vector<URLPattern>({
URLPattern(URLPattern::SCHEME_ALL, "https://uphold.netverify.com/*"),
URLPattern(URLPattern::SCHEME_ALL, "https://*.veriff.me/*"),
})
},
{
URLPattern(URLPattern::SCHEME_ALL, "https://sandbox.uphold.com/"),
std::vector<URLPattern>({
URLPattern(URLPattern::SCHEME_ALL, "https://*.netverify.com/*"),
URLPattern(URLPattern::SCHEME_ALL, "https://*.veriff.me/*"),
})
},
{
URLPattern(URLPattern::SCHEME_ALL, "https://*.1password.com/*"),
std::vector<URLPattern>({URLPattern(URLPattern::SCHEME_ALL,
"https://map.1passwordservices.com/*")})
}
};
for (const auto whitelist : whitelist_patterns) {
if (whitelist.first.MatchesURL(firstPartyOrigin)) {
return std::any_of(whitelist.second.begin(), whitelist.second.end(),
[&subresourceUrl](const URLPattern& pattern) {
return pattern.MatchesURL(subresourceUrl);
});
}
}
return false;
}
} // namespace brave