| OLD | NEW |
| 1 // Copyright 2013 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 #ifndef CONTENT_CHILD_SITE_ISOLATION_POLICY_H_ | 5 #ifndef CONTENT_CHILD_SITE_ISOLATION_STATS_GATHERER_H_ |
| 6 #define CONTENT_CHILD_SITE_ISOLATION_POLICY_H_ | 6 #define CONTENT_CHILD_SITE_ISOLATION_STATS_GATHERER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <string> |
| 9 #include <utility> | |
| 10 | 9 |
| 11 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
| 13 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 14 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 14 #include "content/common/cross_site_document_classifier.h" |
| 15 #include "content/public/common/resource_type.h" | 15 #include "content/public/common/resource_type.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 struct ResourceResponseInfo; | 20 struct ResourceResponseInfo; |
| 21 | 21 |
| 22 // CrossSiteDocumentClassifier implements the cross-site document blocking | |
| 23 // policy (XSDP) for Site Isolation. XSDP will monitor network responses to a | |
| 24 // renderer and block illegal responses so that a compromised renderer cannot | |
| 25 // steal private information from other sites. | |
| 26 // | |
| 27 // SiteIsolationStatsGatherer monitors responses to gather various UMA stats to | 22 // SiteIsolationStatsGatherer monitors responses to gather various UMA stats to |
| 28 // see the compatibility impact of actual deployment of the policy. The UMA stat | 23 // see the compatibility impact of actual deployment of the policy. The UMA stat |
| 29 // categories SiteIsolationStatsGatherer gathers are as follows: | 24 // categories SiteIsolationStatsGatherer gathers are as follows: |
| 30 // | 25 // |
| 31 // SiteIsolation.AllResponses : # of all network responses. | 26 // SiteIsolation.AllResponses : # of all network responses. |
| 32 // SiteIsolation.XSD.DataLength : the length of the first packet of a response. | 27 // SiteIsolation.XSD.DataLength : the length of the first packet of a response. |
| 33 // SiteIsolation.XSD.MimeType (enum): | 28 // SiteIsolation.XSD.MimeType (enum): |
| 34 // # of responses from other sites, tagged with a document mime type. | 29 // # of responses from other sites, tagged with a document mime type. |
| 35 // 0:HTML, 1:XML, 2:JSON, 3:Plain, 4:Others | 30 // 0:HTML, 1:XML, 2:JSON, 3:Plain, 4:Others |
| 36 // SiteIsolation.XSD.[%MIMETYPE].Blocked : | 31 // SiteIsolation.XSD.[%MIMETYPE].Blocked : |
| (...skipping 10 matching lines...) Expand all Loading... |
| 47 // out of SiteIsolation.XSD.[%MIMETYPE].Blocked. | 42 // out of SiteIsolation.XSD.[%MIMETYPE].Blocked. |
| 48 // SiteIsolation.XSD.[%MIMETYPE].NoSniffBlocked.NonRenderableStatusCode : | 43 // SiteIsolation.XSD.[%MIMETYPE].NoSniffBlocked.NonRenderableStatusCode : |
| 49 // # of responses failed to be sniffed for its MIME type, but blocked by | 44 // # of responses failed to be sniffed for its MIME type, but blocked by |
| 50 // "X-Content-Type-Options: nosniff" header, and with non-renderable status | 45 // "X-Content-Type-Options: nosniff" header, and with non-renderable status |
| 51 // code out of SiteIsolation.XSD.[%MIMETYPE].Blocked. | 46 // code out of SiteIsolation.XSD.[%MIMETYPE].Blocked. |
| 52 // SiteIsolation.XSD.[%MIMETYPE].NotBlocked : | 47 // SiteIsolation.XSD.[%MIMETYPE].NotBlocked : |
| 53 // # of responses, but not blocked due to failure of mime sniffing. | 48 // # of responses, but not blocked due to failure of mime sniffing. |
| 54 // SiteIsolation.XSD.[%MIMETYPE].NotBlocked.MaybeJS : | 49 // SiteIsolation.XSD.[%MIMETYPE].NotBlocked.MaybeJS : |
| 55 // # of responses that are plausibly sniffed to be JavaScript. | 50 // # of responses that are plausibly sniffed to be JavaScript. |
| 56 | 51 |
| 57 enum CrossSiteDocumentMimeType { | |
| 58 // Note that these values are used in histograms, and must not change. | |
| 59 CROSS_SITE_DOCUMENT_MIME_TYPE_HTML = 0, | |
| 60 CROSS_SITE_DOCUMENT_MIME_TYPE_XML = 1, | |
| 61 CROSS_SITE_DOCUMENT_MIME_TYPE_JSON = 2, | |
| 62 CROSS_SITE_DOCUMENT_MIME_TYPE_PLAIN = 3, | |
| 63 CROSS_SITE_DOCUMENT_MIME_TYPE_OTHERS = 4, | |
| 64 CROSS_SITE_DOCUMENT_MIME_TYPE_MAX, | |
| 65 }; | |
| 66 | |
| 67 struct SiteIsolationResponseMetaData { | 52 struct SiteIsolationResponseMetaData { |
| 68 SiteIsolationResponseMetaData(); | 53 SiteIsolationResponseMetaData(); |
| 69 | 54 |
| 70 std::string frame_origin; | 55 std::string frame_origin; |
| 71 GURL response_url; | 56 GURL response_url; |
| 72 ResourceType resource_type; | 57 ResourceType resource_type; |
| 73 CrossSiteDocumentMimeType canonical_mime_type; | 58 CrossSiteDocumentMimeType canonical_mime_type; |
| 74 int http_status_code; | 59 int http_status_code; |
| 75 bool no_sniff; | 60 bool no_sniff; |
| 76 }; | 61 }; |
| 77 | 62 |
| 78 // TODO(nick): Move this class into its own file. | |
| 79 class CONTENT_EXPORT SiteIsolationStatsGatherer { | 63 class CONTENT_EXPORT SiteIsolationStatsGatherer { |
| 80 public: | 64 public: |
| 81 // Set activation flag for the UMA data collection for this renderer process. | 65 // Set activation flag for the UMA data collection for this renderer process. |
| 82 static void SetEnabled(bool enabled); | 66 static void SetEnabled(bool enabled); |
| 83 | 67 |
| 84 // Returns any bookkeeping data about the HTTP header information for the | 68 // Returns any bookkeeping data about the HTTP header information for the |
| 85 // request identified by |request_id|. Any data returned should then be | 69 // request identified by |request_id|. Any data returned should then be |
| 86 // passed to OnReceivedFirstChunk() with the first data chunk. | 70 // passed to OnReceivedFirstChunk() with the first data chunk. |
| 87 static linked_ptr<SiteIsolationResponseMetaData> OnReceivedResponse( | 71 static linked_ptr<SiteIsolationResponseMetaData> OnReceivedResponse( |
| 88 const GURL& frame_origin, | 72 const GURL& frame_origin, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 103 FRIEND_TEST_ALL_PREFIXES(SiteIsolationStatsGathererTest, SniffForJS); | 87 FRIEND_TEST_ALL_PREFIXES(SiteIsolationStatsGathererTest, SniffForJS); |
| 104 | 88 |
| 105 SiteIsolationStatsGatherer(); // Not instantiable. | 89 SiteIsolationStatsGatherer(); // Not instantiable. |
| 106 | 90 |
| 107 // Imprecise JS sniffing; only appropriate for collecting UMA stat. | 91 // Imprecise JS sniffing; only appropriate for collecting UMA stat. |
| 108 static bool SniffForJS(base::StringPiece data); | 92 static bool SniffForJS(base::StringPiece data); |
| 109 | 93 |
| 110 DISALLOW_COPY_AND_ASSIGN(SiteIsolationStatsGatherer); | 94 DISALLOW_COPY_AND_ASSIGN(SiteIsolationStatsGatherer); |
| 111 }; | 95 }; |
| 112 | 96 |
| 113 // TODO(nick): Move this class into its own file. | |
| 114 class CONTENT_EXPORT CrossSiteDocumentClassifier { | |
| 115 public: | |
| 116 // Returns the representative mime type enum value of the mime type of | |
| 117 // response. For example, this returns the same value for all text/xml mime | |
| 118 // type families such as application/xml, application/rss+xml. | |
| 119 static CrossSiteDocumentMimeType GetCanonicalMimeType( | |
| 120 const std::string& mime_type); | |
| 121 | |
| 122 // Returns whether this scheme is a target of cross-site document | |
| 123 // policy(XSDP). This returns true only for http://* and https://* urls. | |
| 124 static bool IsBlockableScheme(const GURL& frame_origin); | |
| 125 | |
| 126 // Returns whether the two urls belong to the same sites. | |
| 127 static bool IsSameSite(const GURL& frame_origin, const GURL& response_url); | |
| 128 | |
| 129 // Returns whether there's a valid CORS header for frame_origin. This is | |
| 130 // simliar to CrossOriginAccessControl::passesAccessControlCheck(), but we use | |
| 131 // sites as our security domain, not origins. | |
| 132 // TODO(dsjang): this must be improved to be more accurate to the actual CORS | |
| 133 // specification. For now, this works conservatively, allowing XSDs that are | |
| 134 // not allowed by actual CORS rules by ignoring 1) credentials and 2) | |
| 135 // methods. Preflight requests don't matter here since they are not used to | |
| 136 // decide whether to block a document or not on the client side. | |
| 137 static bool IsValidCorsHeaderSet(const GURL& frame_origin, | |
| 138 const GURL& website_origin, | |
| 139 const std::string& access_control_origin); | |
| 140 | |
| 141 static bool SniffForHTML(base::StringPiece data); | |
| 142 static bool SniffForXML(base::StringPiece data); | |
| 143 static bool SniffForJSON(base::StringPiece data); | |
| 144 | |
| 145 private: | |
| 146 CrossSiteDocumentClassifier(); // Not instantiable. | |
| 147 | |
| 148 DISALLOW_COPY_AND_ASSIGN(CrossSiteDocumentClassifier); | |
| 149 }; | |
| 150 | |
| 151 } // namespace content | 97 } // namespace content |
| 152 | 98 |
| 153 #endif // CONTENT_CHILD_SITE_ISOLATION_POLICY_H_ | 99 #endif // CONTENT_CHILD_SITE_ISOLATION_STATS_GATHERER_H_ |
| OLD | NEW |