Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting/script_request_detector.cc

Issue 1024943002: Add domain request detection to incident reporting service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add DomainRequest incident type to histograms.xml Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/safe_browsing/incident_reporting/script_request_detecto r.h" 5 #include "chrome/browser/safe_browsing/incident_reporting/script_request_detecto r.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/safe_browsing/incident_reporting/domain_request_inciden t.h"
8 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" 9 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h"
9 #include "chrome/browser/safe_browsing/incident_reporting/script_request_inciden t.h" 10 #include "chrome/browser/safe_browsing/incident_reporting/script_request_inciden t.h"
10 #include "chrome/common/safe_browsing/csd.pb.h" 11 #include "chrome/common/safe_browsing/csd.pb.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/render_frame_host.h" 13 #include "content/public/browser/render_frame_host.h"
13 #include "content/public/browser/render_process_host.h" 14 #include "content/public/browser/render_process_host.h"
14 #include "content/public/browser/resource_request_info.h" 15 #include "content/public/browser/resource_request_info.h"
15 #include "content/public/browser/site_instance.h" 16 #include "content/public/browser/site_instance.h"
16 #include "crypto/sha2.h" 17 #include "crypto/sha2.h"
17 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
18 #include "url/gurl.h" 19 #include "url/gurl.h"
19 20
20 namespace { 21 namespace {
21 22
22 const char* const kHashes[] = { 23 const char* const kScriptHashes[] = {
23 "\x2b\x45\xc0\xda\x79\x4c\x65\x19\x4d\x78\x98\x85\x6c\xe8\xbd\x95" 24 "\x2b\x45\xc0\xda\x79\x4c\x65\x19\x4d\x78\x98\x85\x6c\xe8\xbd\x95"
24 "\xf5\x9a\x5a\xf4\x4e\xf9\x9f\x4f\x93\x35\x3b\xa8\x52\xc0\x02\xfb", 25 "\xf5\x9a\x5a\xf4\x4e\xf9\x9f\x4f\x93\x35\x3b\xa8\x52\xc0\x02\xfb",
25 "\x05\xce\x5b\xda\xff\x28\x17\xf9\xc9\x38\x62\x6a\x39\x1b\x76\x56" 26 "\x05\xce\x5b\xda\xff\x28\x17\xf9\xc9\x38\x62\x6a\x39\x1b\x76\x56"
26 "\xe3\xef\xed\x48\x1f\xe3\xae\x93\x4f\xd3\xd2\x96\x87\x53\x45\xf0", 27 "\xe3\xef\xed\x48\x1f\xe3\xae\x93\x4f\xd3\xd2\x96\x87\x53\x45\xf0",
27 "\x3a\x65\x3d\x71\x2d\x3a\xc4\x35\x10\xd7\x01\xb6\xbb\xfb\x49\xda" 28 "\x3a\x65\x3d\x71\x2d\x3a\xc4\x35\x10\xd7\x01\xb6\xbb\xfb\x49\xda"
28 "\x12\xce\x09\xfd\x48\x45\x76\x64\x12\xff\xd4\x7c\x61\x47\x3c\x0b", 29 "\x12\xce\x09\xfd\x48\x45\x76\x64\x12\xff\xd4\x7c\x61\x47\x3c\x0b",
29 "\x95\x8e\x4d\x65\xac\xea\x96\xe5\x11\xd9\xfa\xcc\xcc\xb7\xcd\xb3" 30 "\x95\x8e\x4d\x65\xac\xea\x96\xe5\x11\xd9\xfa\xcc\xcc\xb7\xcd\xb3"
30 "\xcb\x8f\x4d\xf0\xf8\x72\xa0\xc5\x87\x02\xad\xe4\x1f\x3d\xfa\xf2", 31 "\xcb\x8f\x4d\xf0\xf8\x72\xa0\xc5\x87\x02\xad\xe4\x1f\x3d\xfa\xf2",
31 "\x2b\x8f\x58\x38\xeb\x87\x5d\xa0\x14\x90\x95\x89\x04\xd3\xe5\x89" 32 "\x2b\x8f\x58\x38\xeb\x87\x5d\xa0\x14\x90\x95\x89\x04\xd3\xe5\x89"
32 "\xc5\xd7\x7a\xb6\x48\x53\x18\xfe\x71\x3a\x6a\xfd\xf0\xb3\x6e\xa8", 33 "\xc5\xd7\x7a\xb6\x48\x53\x18\xfe\x71\x3a\x6a\xfd\xf0\xb3\x6e\xa8",
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 "\x21\x66\x33\xff\xc3\xfa\xe1\x7a\xa1\x06\xf2\x9e\x2f\xc6\xcc\x93" 94 "\x21\x66\x33\xff\xc3\xfa\xe1\x7a\xa1\x06\xf2\x9e\x2f\xc6\xcc\x93"
94 "\x1e\x62\x17\xf1\xcc\x02\x2f\x39\x80\xee\x34\x4a\x85\xc8\x99\xed", 95 "\x1e\x62\x17\xf1\xcc\x02\x2f\x39\x80\xee\x34\x4a\x85\xc8\x99\xed",
95 "\x9b\x62\xc6\x2b\xc9\xb0\xf9\xbd\x93\x1a\xfd\xed\xfb\x68\xa0\xc2" 96 "\x9b\x62\xc6\x2b\xc9\xb0\xf9\xbd\x93\x1a\xfd\xed\xfb\x68\xa0\xc2"
96 "\x15\xfe\x34\xea\xc4\x89\x73\x9e\x70\x93\xe1\x1f\x4a\x75\xbe\x09", 97 "\x15\xfe\x34\xea\xc4\x89\x73\x9e\x70\x93\xe1\x1f\x4a\x75\xbe\x09",
97 "\xb9\xe4\x66\x44\xea\x77\xe1\x74\x3d\x92\xcf\x6c\x20\x7e\xbf\x46" 98 "\xb9\xe4\x66\x44\xea\x77\xe1\x74\x3d\x92\xcf\x6c\x20\x7e\xbf\x46"
98 "\xfd\x4f\x4e\x82\x17\xa8\x7d\x3d\x19\xd4\xda\xde\x75\x74\xf1\x13", 99 "\xfd\x4f\x4e\x82\x17\xa8\x7d\x3d\x19\xd4\xda\xde\x75\x74\xf1\x13",
99 "\x8b\x2e\x30\xfa\x2e\xe1\xa1\x8e\xb6\x00\xb9\xe3\xc2\xc9\xa4\xad" 100 "\x8b\x2e\x30\xfa\x2e\xe1\xa1\x8e\xb6\x00\xb9\xe3\xc2\xc9\xa4\xad"
100 "\x70\x03\x72\xea\xa8\x68\xdc\x95\x43\x6d\xdf\x40\x26\x58\xde\xe6", 101 "\x70\x03\x72\xea\xa8\x68\xdc\x95\x43\x6d\xdf\x40\x26\x58\xde\xe6",
101 }; 102 };
102 103
104 const char* const kDomainHashes[] = {
105 "\x1e\x11\x37\x30\xc2\x8a\xf5\xde\xac\x4c\xf3\x6b\x45\xbf\xc2\x64"
106 "\x86\x73\x44\xad\xb5\x81\xb0\xc8\x54\x58\x6e\x6b\x6f\x92\x50\xc9",
107 "\xac\xc0\x51\x88\x40\xfe\xdd\x9b\x02\x5b\x58\x8a\xe7\x19\x58\xaa"
108 "\x45\xb9\x19\x7e\x8a\xf0\xd0\xa8\x2a\x53\x6e\xc4\x38\x31\xc9\x96",
109 "\x2b\xbe\xdf\x89\x33\x2c\xe4\xc7\xcf\xca\x65\xfb\x91\x1c\x9d\x3a"
110 "\x4e\x51\xbe\x56\xe3\xfa\x2c\x32\x78\x6b\x90\x03\x68\xf4\x3f\xc5",
111 "\x5b\x81\x16\xa0\xce\xa4\x6d\x57\xbd\x38\x7f\xd0\x85\x25\x59\x53"
112 "\xaf\x46\xf8\x24\x44\xde\x6e\x3e\x24\x96\x97\x9a\x7c\x53\xbc\xdf",
113 "\x07\x9e\x8d\xe6\x1e\x5e\xb8\x35\x24\x84\x0f\xd9\x08\x2a\x99\xf3"
114 "\x28\x73\xac\x7b\x67\x01\x33\xa3\x49\xf8\xad\xb7\xef\xc6\xb4\xb8",
115 "\x9e\xb5\x08\x1e\x63\x1a\x76\xb1\x32\x6f\xf1\xf7\xad\x31\xbf\xf8"
116 "\xa1\x65\x4a\x90\x6d\x08\xc5\xb4\xca\xb5\x7a\x83\xc9\xbf\x2f\xcc",
117 "\x8e\xc5\xf8\x8f\x1e\x16\x5a\x6c\x32\x89\x03\xca\x57\xd2\x5b\xda"
118 "\x90\xac\x27\x87\x8d\x31\x0d\x3e\xae\x23\xa9\xfd\x90\x3a\xca\x44",
119 "\xae\xad\x0e\x56\xa8\x15\x77\xfd\x7e\x57\x31\x73\x09\xd0\x64\x17"
120 "\x39\xdb\x81\x5f\x21\x9a\x68\x7c\x93\x31\xd6\x08\x44\x9e\xe0\x8c",
121 "\xe9\x50\x69\xc7\xfe\xd2\x6b\xc6\x07\xd5\x0e\x4d\x66\x0f\xf7\x7e"
122 "\xc8\xdd\xb8\xba\xdd\x77\x24\x50\x22\x4a\xfe\xb0\x17\x6c\x97\x70",
123 "\x2a\xa2\xd3\xaa\x45\x98\xf7\x02\x21\x25\xc0\xe2\x8d\x56\x57\xe5"
124 "\xc5\x50\x63\x86\x1a\x31\xfd\xae\x68\x63\x68\x60\x97\xaf\x70\xb9",
125 "\xb3\xc9\x4e\x79\x0b\x34\xec\x92\xba\x62\x6d\x0a\x1a\xe8\xb8\xed"
126 "\xf6\x32\xb6\x46\xeb\x48\x12\xa2\x7c\x97\x8c\x01\x5f\xab\x00\xf1",
127 "\xb1\x46\x39\xdc\x41\x12\xdf\x27\x41\x20\x0c\x29\x34\xc0\x76\x3f"
128 "\xdc\xfa\x19\x4d\x76\xfe\x7b\xce\x0e\x22\x00\x36\x0d\xc8\xaa\x61",
129 "\xfb\x3a\xc8\xdc\x0e\x89\xa0\x6a\xf5\xe4\x6d\x8b\x47\x05\xdb\x0b"
130 "\x27\xeb\x15\x41\x14\xdc\xbc\xa1\x3a\x63\x10\xc2\xb6\x28\xcd\xc9",
131 "\x98\xa0\x19\x03\x97\x3b\xee\x5b\x7d\x11\xde\xa4\xd2\x07\x58\xa0"
132 "\x5d\x4a\x45\x85\x95\x5d\xd5\x82\x74\x12\x64\xbf\x7a\x3d\x84\x84",
133 "\xc9\x05\x29\x1e\x3f\x37\x68\x4a\xac\x50\x36\x0b\xc8\x31\x4d\x5c"
134 "\xa7\x3b\x3d\x5c\x1b\xeb\xd3\xcc\xbb\x9e\x74\x64\x69\x42\x23\x6c",
135 "\xe9\x68\xe5\x82\xc8\xb6\x78\xc4\xb2\xcc\xfa\xa2\xd2\x6c\x58\x89"
136 "\x59\x41\xee\x98\x25\x64\xd4\x12\x59\x81\x2c\xea\xa6\xd3\x23\xd8",
137 "\x7f\xd8\x3f\x84\x70\xfd\x08\x9b\xe6\x66\x65\x77\x4a\x0e\x20\x25"
138 "\xc9\x9a\xc0\x6c\x12\x82\x00\x08\x4a\x62\xe8\x1c\xa7\xb3\x90\x07",
139 "\xaa\x45\x3b\x66\xab\x46\x95\x21\x92\x5f\x7c\xc3\xab\xa3\x3e\x5e"
140 "\x23\x14\x4a\x50\xfa\x5d\xb8\xf5\x25\x29\x42\x23\x6c\x23\x95\xeb",
141 "\xf9\xcf\x8a\x1c\xc0\x7f\x38\x8d\x20\x5d\xe9\x88\x00\xdf\x6b\xb3"
142 "\xc4\x39\xa4\x4f\x61\x65\x6e\x43\x35\x54\x2c\x15\x50\xc3\xa3\x21",
143 "\xc4\x1b\x1a\x9d\xdd\x18\xd3\xb7\xdd\x2c\x02\x07\xfd\x63\x3b\x53"
144 "\x7b\xe0\x1d\x17\xcf\x15\xc9\x25\xa8\x76\xd1\x41\x9e\x62\x34\x0a",
145 "\xc3\xeb\x5e\x05\x55\x1e\x63\xe9\x6e\xa7\x98\x92\xd7\x3b\x45\xe1"
146 "\x5f\xbc\xc4\xf0\x2f\xb1\x9f\xbf\x4b\x1f\xe5\xdd\xde\x76\x2a\x77",
147 "\xfc\xd4\xa8\x97\x50\x0d\xba\x15\xac\x3c\x2b\x6e\x2b\x79\x93\xcd"
148 "\x18\x1a\xb1\xad\x32\x04\x27\x01\x39\xf7\x6d\x7a\x39\xb5\x92\x35",
149 "\x97\x94\xec\x59\x45\xd8\xfe\xa3\x73\x1f\x03\xe6\xb2\xfc\x2e\xe8"
150 "\xf7\x95\xe3\xaf\x8f\x97\x01\x6f\xef\x6b\x7b\xee\x41\x5e\x27\x7e",
151 "\x75\xc1\x70\x94\x68\xf6\xcc\x07\xb7\xbe\x0b\x84\x0c\x64\xa8\x47"
152 "\x4e\xea\x7f\x75\x3b\xcb\x28\x39\xab\xe5\x14\x8a\xb4\x5a\x38\xb2",
153 "\x94\x48\xfd\x84\x30\xba\x7d\x81\x04\xdc\xbb\x16\xa1\x06\xa9\xe4"
154 "\xb1\xa7\xff\xc5\x13\x22\xed\x4e\x05\xfe\xf9\xb8\x69\xfe\x23\xd4",
155 "\xb5\x32\x33\x46\x6c\x29\xe2\x74\xa6\x63\x60\x70\xdb\x20\x15\x12"
156 "\x0a\x67\xf0\x3a\xad\xf9\x0c\x33\x91\x4c\x90\x5c\x55\x92\x1f\xf8",
157 "\x16\xe6\x9c\xdf\xa2\x18\x13\x60\xe4\x2b\xb3\x07\x29\xa8\xd8\x1b"
158 "\xc5\xa8\xd1\x85\x42\x67\x57\x81\x55\x34\x97\x1d\x8c\xe9\xee\xb7",
159 "\x28\x3f\x74\x64\xb2\x15\xfc\x1b\x75\xcd\x69\x88\x04\x1b\x27\x62"
160 "\xd0\xc2\xdc\xbe\x31\xbe\xb5\x30\xa3\x6e\x01\xdd\x0f\x4e\x31\x2b",
161 "\x75\xc2\x30\x5b\xa3\x9b\xff\x0d\xdc\x75\xdf\x20\x8e\xa1\xe6\x5c"
162 "\x17\xab\xf0\x58\x06\xf3\xda\x9f\xa5\xaa\x98\xfe\x1a\x7e\x74\x2b",
163 "\x3c\xc1\x60\xc5\xd0\x56\x0d\x08\xd5\x19\xbf\x08\x51\x18\x9b\xc8"
164 "\xdd\x8d\x58\x5f\x1d\x75\x88\x14\x73\x8c\xda\x66\x12\x94\x8a\xeb",
165 "\x54\xba\x7d\x21\x4e\x4e\xc2\xf3\x37\x37\x86\xcd\xbe\x7b\x89\x42"
166 "\xa9\x7b\x3b\xec\x69\x49\x6c\x1c\x58\xb8\x4d\xe8\x06\x1c\x88\x37",
167 "\x62\xef\x4d\x5f\xa4\x64\x80\xd6\x97\xd2\xd0\xbd\x31\x30\x03\x5f"
168 "\x22\x37\x8d\x48\xdd\x8a\xb2\xf0\xe3\x57\x35\x98\x37\x70\x32\x25",
169 "\x23\x93\xc0\xa1\xd4\x27\xbd\x64\x65\x86\xe1\xa4\x86\x99\x99\x47"
170 "\x89\xf9\x69\xe2\xba\xce\x7c\x42\xc7\x5d\xbc\xe9\x14\x73\x1c\x8d",
171 "\x10\xe5\x75\x6d\x09\x43\xb3\xca\x0d\x1b\x78\xd1\xc2\x1a\xe5\xc0"
172 "\xd8\x29\x57\x86\x87\xe3\x43\x95\x87\xf6\x92\x83\x5e\x08\x4f\x7a",
173 "\x1c\xf9\xec\x01\x62\xbe\x78\x9b\x0e\x42\x3b\x7e\x70\x47\x27\x46"
174 "\x34\x52\x6e\x45\x1b\x60\x6e\xaf\xcb\x74\x8e\xdd\xbd\xe3\x4f\x5a",
175 "\x62\x02\x40\x4d\x50\xd8\x2a\xd0\x67\xdc\xb5\xc7\xfc\x13\xe9\x66"
176 "\x6a\x14\x33\x7e\xef\xf7\x20\x83\x4c\xf6\x32\xf4\x7a\x75\x32\xa1",
177 "\x35\x89\xab\x5d\xeb\xd5\x4c\x3a\x0f\x34\xeb\x35\x39\x9d\x51\xda"
178 "\x7c\x98\x40\xb7\xd4\xca\x5b\x5e\x3f\x82\x22\xbb\xd6\x56\x42\x78",
179 "\x30\x91\xf8\x24\xa3\xb6\x66\xb0\xc5\xe6\xe0\xfc\xa8\xfc\x2c\x9f"
180 "\x53\x09\x3f\xe5\x4f\x19\xab\xae\x09\xbc\x40\xa9\xd1\x37\x8e\x84",
181 "\xfa\x5a\x2f\xf0\xb0\x3e\x81\xbb\x7b\x4b\xc0\xf0\x67\xf1\xbe\x9d"
182 "\x86\x87\x51\xe6\x72\x34\x70\x02\xc2\xec\xb5\x66\xe7\xd1\x4d\x55",
183 "\x10\x24\x54\x8f\xe4\x06\x49\x6b\x0f\xcf\x95\x5c\xf9\xa6\xdc\xa9"
184 "\xc0\x7d\xda\xda\x78\x21\x57\x40\xdb\xb3\x54\x5f\x3b\x53\x48\xee",
185 "\xf7\xf2\x47\x19\x6e\x7d\x14\x08\x4b\xf3\x6f\x5c\x40\x19\x11\x54"
186 "\x68\xa5\x0d\xde\x6e\xba\x5e\x1b\x34\x04\x72\x41\x55\x31\xb1\x18",
187 "\xb6\xfa\x48\xa8\xd7\x20\xde\x56\x8c\x90\x81\xac\xaf\xd8\xf2\xe6"
188 "\xab\x56\xbb\x64\x1e\xbc\x93\x56\x3f\xce\xac\xd9\xa7\x4d\xa8\x40",
189 "\xfb\x8b\x14\x2e\xa8\x6a\x77\xaf\x7c\x13\x8a\x38\x6b\xd9\xf1\xc8"
190 "\x87\x63\x8d\x00\xe4\xac\xf2\x11\x4a\x1f\x39\x57\x1f\xa6\xca\xdf",
191 "\xba\xad\xe8\xdb\x70\x80\x8d\xbd\x3c\xc7\x6b\xd6\x02\x6a\x41\x40"
192 "\x62\x45\x7b\x18\x65\x94\xf3\x56\xc5\x24\x1e\xcb\x81\x8d\x45\x09",
193 "\x8f\xd5\xf8\xd3\x29\x82\x94\x51\xa8\xe6\x3a\x9d\x3a\xc7\x51\xe1"
194 "\xd3\x54\x32\xcb\x2c\x20\x98\x5a\x70\x04\x18\xfd\x49\x75\x85\x6e",
195 "\x90\x73\x6e\x8e\xe9\x75\xdf\xc6\x7e\xe7\x00\xe4\x4d\xc7\x0f\x04"
196 "\xe6\x58\x78\xa3\xbc\x98\x22\xb9\x38\xe0\xf0\x67\xe2\xa9\x8e\x1f",
197 "\x99\x3b\x39\x8e\x69\x7f\x28\xfd\x09\x8d\xc9\xed\xf9\x57\x0e\x41"
198 "\x1b\x41\x48\x40\x37\xf4\x77\xd3\x07\xbd\x82\xc6\xda\x16\xa8\xec",
199 "\x6d\x57\xf2\xd8\xf9\x6a\x82\x76\x1d\xb6\x8a\xe8\xb6\x3a\xcc\xd4"
200 "\x30\x59\xdd\xa6\x18\x64\xac\xd9\x83\x80\x7c\x75\x7a\xdf\x20\xfe",
201 "\x33\x5a\x23\xb0\xde\xd3\x7f\xc2\x96\xb7\x2e\xd4\x8a\xdc\x65\x0e"
202 "\xe6\x95\x6b\x41\xf0\xfe\xa0\xdf\xdf\x28\x73\xce\x6e\x1d\x79\x2d",
203 "\x13\xe3\xbc\x23\xb3\xf2\x10\x76\x10\xe8\x83\x8b\x83\xf0\x5e\x8d"
204 "\x4a\x8e\xf3\x98\x4d\x05\x03\x53\x69\xe0\xc0\x21\x9f\x69\x3f\x77",
205 "\xba\x88\x57\x60\x31\x4c\xd9\x6b\x21\x3e\xa3\x88\xe7\x45\x6c\x41"
206 "\x91\x66\xf2\x08\xd0\x89\xe6\x39\x68\x6c\xb8\x7a\xd7\x7d\x9f\x76",
207 "\xcd\xd5\x93\x5a\xe2\xdb\xf3\x63\xeb\xfd\xd0\x88\x49\x7d\xf6\x29"
208 "\xbf\x1f\xee\x3a\xda\xa1\x95\x38\x4d\xc3\x91\x21\xce\x01\xd1\x8d",
209 };
210
103 Profile* GetProfileForRenderProcessId(int render_process_id) { 211 Profile* GetProfileForRenderProcessId(int render_process_id) {
104 // How to get a profile from a RenderProcess id: 212 // How to get a profile from a RenderProcess id:
105 // 1) Get the RenderProcessHost 213 // 1) Get the RenderProcessHost
106 // 2) From 1) Get the BrowserContext 214 // 2) From 1) Get the BrowserContext
107 // 3) From 2) Get the Profile. 215 // 3) From 2) Get the Profile.
108 Profile* profile = nullptr; 216 Profile* profile = nullptr;
109 content::RenderProcessHost* render_process_host = 217 content::RenderProcessHost* render_process_host =
110 content::RenderProcessHost::FromID(render_process_id); 218 content::RenderProcessHost::FromID(render_process_id);
111 if (render_process_host) { 219 if (render_process_host) {
112 content::BrowserContext* browser_context = 220 content::BrowserContext* browser_context =
(...skipping 14 matching lines...) Expand all
127 235
128 } // namespace 236 } // namespace
129 237
130 namespace safe_browsing { 238 namespace safe_browsing {
131 239
132 ScriptRequestDetector::ScriptRequestDetector( 240 ScriptRequestDetector::ScriptRequestDetector(
133 scoped_ptr<IncidentReceiver> incident_receiver) 241 scoped_ptr<IncidentReceiver> incident_receiver)
134 : incident_receiver_(incident_receiver.Pass()), 242 : incident_receiver_(incident_receiver.Pass()),
135 allow_null_profile_for_testing_(false), 243 allow_null_profile_for_testing_(false),
136 weak_ptr_factory_(this) { 244 weak_ptr_factory_(this) {
137 InitializeScriptSet(); 245 InitializeHashSets();
138 } 246 }
139 247
140 ScriptRequestDetector::~ScriptRequestDetector() { 248 ScriptRequestDetector::~ScriptRequestDetector() {
141 } 249 }
142 250
143 void ScriptRequestDetector::OnResourceRequest(const net::URLRequest* request) { 251 void ScriptRequestDetector::OnResourceRequest(const net::URLRequest* request) {
144 // Only look at actual net requests (e.g., not chrome-extensions://id/foo.js). 252 // Only look at actual net requests (e.g., not chrome-extensions://id/foo.js).
145 if (!request->url().SchemeIsHTTPOrHTTPS()) 253 if (!request->url().SchemeIsHTTPOrHTTPS())
146 return; 254 return;
147 255
256 DetectDomainRequests(request);
257 DetectScriptRequests(request);
258 }
259
260 void ScriptRequestDetector::DetectDomainRequests(
261 const net::URLRequest* request) {
262 std::string domain(request->url().host());
263 std::string domain_digest(crypto::kSHA256Length, '\0');
264 crypto::SHA256HashString(domain.c_str(), &domain_digest[0],
grt (UTC plus 2) 2015/03/20 20:50:04 use request->url().host() directly here
romanl 2015/03/26 22:01:47 Done.
265 crypto::kSHA256Length);
266
267 if (domain_set_.count(domain_digest)) {
268 DVLOG(1) << "Domain detector match found.";
269
270 scoped_ptr<ClientIncidentReport_IncidentData_DomainRequestIncident>
271 incident_data(
272 new ClientIncidentReport_IncidentData_DomainRequestIncident());
273 incident_data->set_domain_digest(domain_digest);
274
275 // This next bit of work needs a profile, so has to happen on the UI
276 // thread.
277 int render_process_id = 0;
278 int render_frame_id = 0;
279 content::ResourceRequestInfo::GetRenderFrameForRequest(
280 request, &render_process_id, &render_frame_id);
281
282 content::BrowserThread::PostTask(
283 content::BrowserThread::UI, FROM_HERE,
284 base::Bind(&ScriptRequestDetector::ReportDomainIncidentOnUIThread,
285 weak_ptr_factory_.GetWeakPtr(), render_process_id,
286 render_frame_id, base::Passed(&incident_data)));
287 }
288 }
289
290 void ScriptRequestDetector::DetectScriptRequests(
291 const net::URLRequest* request) {
148 const content::ResourceRequestInfo* request_info = 292 const content::ResourceRequestInfo* request_info =
149 content::ResourceRequestInfo::ForRequest(request); 293 content::ResourceRequestInfo::ForRequest(request);
150 294
151 if (request_info->GetResourceType() != content::RESOURCE_TYPE_SCRIPT) 295 if (request_info->GetResourceType() != content::RESOURCE_TYPE_SCRIPT)
152 return; 296 return;
153 297
154 DVLOG(1) << "Script request: " << request->url().spec(); 298 DVLOG(1) << "Script request: " << request->url().spec();
155 299
156 std::string url(request->url().host() + request->url().path()); 300 std::string url(request->url().host() + request->url().path());
157 std::string script_digest(crypto::kSHA256Length, '\0'); 301 std::string script_digest(crypto::kSHA256Length, '\0');
(...skipping 10 matching lines...) Expand all
168 312
169 // This next bit of work needs a profile, so has to happen on the UI 313 // This next bit of work needs a profile, so has to happen on the UI
170 // thread. 314 // thread.
171 int render_process_id = 0; 315 int render_process_id = 0;
172 int render_frame_id = 0; 316 int render_frame_id = 0;
173 content::ResourceRequestInfo::GetRenderFrameForRequest( 317 content::ResourceRequestInfo::GetRenderFrameForRequest(
174 request, &render_process_id, &render_frame_id); 318 request, &render_process_id, &render_frame_id);
175 319
176 content::BrowserThread::PostTask( 320 content::BrowserThread::PostTask(
177 content::BrowserThread::UI, FROM_HERE, 321 content::BrowserThread::UI, FROM_HERE,
178 base::Bind(&ScriptRequestDetector::ReportIncidentOnUIThread, 322 base::Bind(&ScriptRequestDetector::ReportScriptIncidentOnUIThread,
179 weak_ptr_factory_.GetWeakPtr(), render_process_id, 323 weak_ptr_factory_.GetWeakPtr(), render_process_id,
180 render_frame_id, base::Passed(&incident_data))); 324 render_frame_id, base::Passed(&incident_data)));
181 } 325 }
182 } 326 }
183 327
184 void ScriptRequestDetector::set_allow_null_profile_for_testing( 328 void ScriptRequestDetector::set_allow_null_profile_for_testing(
185 bool allow_null_profile_for_testing) { 329 bool allow_null_profile_for_testing) {
186 allow_null_profile_for_testing_ = allow_null_profile_for_testing; 330 allow_null_profile_for_testing_ = allow_null_profile_for_testing;
187 } 331 }
188 332
189 void ScriptRequestDetector::InitializeScriptSet() { 333 void ScriptRequestDetector::InitializeHashSets() {
190 // Store a hashed set of decoded string hashes. Probably slower than a linear 334 // Store a hashed set of decoded string hashes. Probably slower than a linear
191 // search for this size list, but this is only temporary. 335 // search for this size list, but this is only temporary.
192 for (const char* encoded_hash : kHashes) 336 for (const char* encoded_hash : kScriptHashes)
193 script_set_.insert(std::string(encoded_hash, crypto::kSHA256Length)); 337 script_set_.insert(std::string(encoded_hash, crypto::kSHA256Length));
338
339 for (const char* encoded_hash : kDomainHashes)
340 domain_set_.insert(std::string(encoded_hash, crypto::kSHA256Length));
194 } 341 }
195 342
196 void ScriptRequestDetector::ReportIncidentOnUIThread( 343 void ScriptRequestDetector::ReportDomainIncidentOnUIThread(
344 int render_process_id,
345 int render_frame_id,
346 scoped_ptr<ClientIncidentReport_IncidentData_DomainRequestIncident>
347 incident_data) {
348 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
349
350 Profile* profile = GetProfileForRenderProcessId(render_process_id);
351 if (profile || allow_null_profile_for_testing_) {
352 // Add the URL obtained from the RenderFrameHost, if available.
353 GURL host_url = GetUrlForRenderFrameId(render_process_id, render_frame_id);
354 if (host_url.is_valid())
355 incident_data->set_request_origin(host_url.GetOrigin().spec());
356
357 incident_receiver_->AddIncidentForProfile(
358 profile,
359 make_scoped_ptr(new DomainRequestIncident(incident_data.Pass())));
360 }
361 }
362
363 void ScriptRequestDetector::ReportScriptIncidentOnUIThread(
197 int render_process_id, 364 int render_process_id,
198 int render_frame_id, 365 int render_frame_id,
199 scoped_ptr<ClientIncidentReport_IncidentData_ScriptRequestIncident> 366 scoped_ptr<ClientIncidentReport_IncidentData_ScriptRequestIncident>
200 incident_data) { 367 incident_data) {
201 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 368 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
202 369
203 Profile* profile = GetProfileForRenderProcessId(render_process_id); 370 Profile* profile = GetProfileForRenderProcessId(render_process_id);
204 if (profile || allow_null_profile_for_testing_) { 371 if (profile || allow_null_profile_for_testing_) {
205 // Add the URL obtained from the RenderFrameHost, if available. 372 // Add the URL obtained from the RenderFrameHost, if available.
206 GURL host_url = GetUrlForRenderFrameId(render_process_id, render_frame_id); 373 GURL host_url = GetUrlForRenderFrameId(render_process_id, render_frame_id);
207 if (host_url.is_valid()) 374 if (host_url.is_valid())
208 incident_data->set_inclusion_origin(host_url.GetOrigin().spec()); 375 incident_data->set_inclusion_origin(host_url.GetOrigin().spec());
209 376
210 incident_receiver_->AddIncidentForProfile( 377 incident_receiver_->AddIncidentForProfile(
211 profile, 378 profile,
212 make_scoped_ptr(new ScriptRequestIncident(incident_data.Pass()))); 379 make_scoped_ptr(new ScriptRequestIncident(incident_data.Pass())));
213 } 380 }
214 } 381 }
215 382
216 } // namespace safe_browsing 383 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698