OLD | NEW |
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 "content/child/site_isolation_stats_gatherer.h" | 5 #include "content/child/site_isolation_stats_gatherer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // See if this is for navigation. If it is, don't block it, under the | 119 // See if this is for navigation. If it is, don't block it, under the |
120 // assumption that we will put it in an appropriate process. | 120 // assumption that we will put it in an appropriate process. |
121 if (IsResourceTypeFrame(resource_type)) | 121 if (IsResourceTypeFrame(resource_type)) |
122 return nullptr; | 122 return nullptr; |
123 | 123 |
124 if (!CrossSiteDocumentClassifier::IsBlockableScheme(response_url)) | 124 if (!CrossSiteDocumentClassifier::IsBlockableScheme(response_url)) |
125 return nullptr; | 125 return nullptr; |
126 | 126 |
127 // TODO(csharrison): Add a path for IsSameSite/IsValidCorsHeaderSet to take an | 127 // TODO(csharrison): Add a path for IsSameSite/IsValidCorsHeaderSet to take an |
128 // Origin. | 128 // Origin. |
129 GURL frame_origin_url = frame_origin.GetURL(); | 129 if (CrossSiteDocumentClassifier::IsSameSite(frame_origin, response_url)) |
130 if (CrossSiteDocumentClassifier::IsSameSite(frame_origin_url, response_url)) | |
131 return nullptr; | 130 return nullptr; |
132 | 131 |
133 CrossSiteDocumentMimeType canonical_mime_type = | 132 CrossSiteDocumentMimeType canonical_mime_type = |
134 CrossSiteDocumentClassifier::GetCanonicalMimeType(info.mime_type); | 133 CrossSiteDocumentClassifier::GetCanonicalMimeType(info.mime_type); |
135 | 134 |
136 if (canonical_mime_type == CROSS_SITE_DOCUMENT_MIME_TYPE_OTHERS) | 135 if (canonical_mime_type == CROSS_SITE_DOCUMENT_MIME_TYPE_OTHERS) |
137 return nullptr; | 136 return nullptr; |
138 | 137 |
139 // Every CORS request should have the Access-Control-Allow-Origin header even | 138 // Every CORS request should have the Access-Control-Allow-Origin header even |
140 // if it is preceded by a pre-flight request. Therefore, if this is a CORS | 139 // if it is preceded by a pre-flight request. Therefore, if this is a CORS |
141 // request, it has this header. response.httpHeaderField() internally uses | 140 // request, it has this header. response.httpHeaderField() internally uses |
142 // case-insensitive matching for the header name. | 141 // case-insensitive matching for the header name. |
143 std::string access_control_origin; | 142 std::string access_control_origin; |
144 | 143 |
145 // We can use a case-insensitive header name for EnumerateHeader(). | 144 // We can use a case-insensitive header name for EnumerateHeader(). |
146 info.headers->EnumerateHeader(NULL, "access-control-allow-origin", | 145 info.headers->EnumerateHeader(NULL, "access-control-allow-origin", |
147 &access_control_origin); | 146 &access_control_origin); |
148 if (CrossSiteDocumentClassifier::IsValidCorsHeaderSet( | 147 if (CrossSiteDocumentClassifier::IsValidCorsHeaderSet( |
149 frame_origin_url, response_url, access_control_origin)) | 148 frame_origin, response_url, access_control_origin)) { |
150 return nullptr; | 149 return nullptr; |
| 150 } |
151 | 151 |
152 // Real XSD data collection starts from here. | 152 // Real XSD data collection starts from here. |
153 std::string no_sniff; | 153 std::string no_sniff; |
154 info.headers->EnumerateHeader(NULL, "x-content-type-options", &no_sniff); | 154 info.headers->EnumerateHeader(NULL, "x-content-type-options", &no_sniff); |
155 | 155 |
156 std::unique_ptr<SiteIsolationResponseMetaData> resp_data( | 156 std::unique_ptr<SiteIsolationResponseMetaData> resp_data( |
157 new SiteIsolationResponseMetaData); | 157 new SiteIsolationResponseMetaData); |
158 resp_data->frame_origin = frame_origin_url.spec(); | |
159 resp_data->response_url = response_url; | 158 resp_data->response_url = response_url; |
160 resp_data->resource_type = resource_type; | 159 resp_data->resource_type = resource_type; |
161 resp_data->canonical_mime_type = canonical_mime_type; | 160 resp_data->canonical_mime_type = canonical_mime_type; |
162 resp_data->http_status_code = info.headers->response_code(); | 161 resp_data->http_status_code = info.headers->response_code(); |
163 resp_data->no_sniff = base::LowerCaseEqualsASCII(no_sniff, "nosniff"); | 162 resp_data->no_sniff = base::LowerCaseEqualsASCII(no_sniff, "nosniff"); |
164 | 163 |
165 return resp_data; | 164 return resp_data; |
166 } | 165 } |
167 | 166 |
168 bool SiteIsolationStatsGatherer::OnReceivedFirstChunk( | 167 bool SiteIsolationStatsGatherer::OnReceivedFirstChunk( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 254 } |
256 | 255 |
257 bool SiteIsolationStatsGatherer::SniffForJS(base::StringPiece data) { | 256 bool SiteIsolationStatsGatherer::SniffForJS(base::StringPiece data) { |
258 // The purpose of this function is to try to see if there's any possibility | 257 // The purpose of this function is to try to see if there's any possibility |
259 // that this data can be JavaScript (superset of JS). Search for "var " for JS | 258 // that this data can be JavaScript (superset of JS). Search for "var " for JS |
260 // detection. This is a real hack and should only be used for stats gathering. | 259 // detection. This is a real hack and should only be used for stats gathering. |
261 return data.find("var ") != base::StringPiece::npos; | 260 return data.find("var ") != base::StringPiece::npos; |
262 } | 261 } |
263 | 262 |
264 } // namespace content | 263 } // namespace content |
OLD | NEW |