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

Side by Side Diff: content/child/site_isolation_policy.h

Issue 1181493002: [Patch 3 of 6] Split out content/child's SiteIsolationPolicy into two new classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rename_policy_to_sniffer2
Patch Set: Yet more comment fixes. Created 5 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_POLICY_H_
6 #define CONTENT_CHILD_SITE_ISOLATION_POLICY_H_ 6 #define CONTENT_CHILD_SITE_ISOLATION_POLICY_H_
7 7
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "content/common/content_export.h" 14 #include "content/common/content_export.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 // SiteIsolationPolicy implements the cross-site document blocking policy (XSDP) 22 // CrossSiteDocumentClassifier implements the cross-site document blocking
23 // for Site Isolation. XSDP will monitor network responses to a renderer and 23 // policy (XSDP) for Site Isolation. XSDP will monitor network responses to a
24 // block illegal responses so that a compromised renderer cannot steal private 24 // renderer and block illegal responses so that a compromised renderer cannot
25 // information from other sites. For now SiteIsolationPolicy monitors responses 25 // steal private information from other sites.
26 // to gather various UMA stats to see the compatibility impact of actual 26 //
27 // deployment of the policy. The UMA stat categories SiteIsolationPolicy gathers 27 // SiteIsolationStatsGatherer monitors responses to gather various UMA stats to
28 // are as follows: 28 // see the compatibility impact of actual deployment of the policy. The UMA stat
29 // categories SiteIsolationStatsGatherer gathers are as follows:
29 // 30 //
30 // SiteIsolation.AllResponses : # of all network responses. 31 // SiteIsolation.AllResponses : # of all network responses.
31 // SiteIsolation.XSD.DataLength : the length of the first packet of a response. 32 // SiteIsolation.XSD.DataLength : the length of the first packet of a response.
32 // SiteIsolation.XSD.MimeType (enum): 33 // SiteIsolation.XSD.MimeType (enum):
33 // # of responses from other sites, tagged with a document mime type. 34 // # of responses from other sites, tagged with a document mime type.
34 // 0:HTML, 1:XML, 2:JSON, 3:Plain, 4:Others 35 // 0:HTML, 1:XML, 2:JSON, 3:Plain, 4:Others
35 // SiteIsolation.XSD.[%MIMETYPE].Blocked : 36 // SiteIsolation.XSD.[%MIMETYPE].Blocked :
36 // blocked # of cross-site document responses grouped by sniffed MIME type. 37 // blocked # of cross-site document responses grouped by sniffed MIME type.
37 // SiteIsolation.XSD.[%MIMETYPE].Blocked.RenderableStatusCode : 38 // SiteIsolation.XSD.[%MIMETYPE].Blocked.RenderableStatusCode :
38 // # of responses with renderable status code, 39 // # of responses with renderable status code,
(...skipping 27 matching lines...) Expand all
66 SiteIsolationResponseMetaData(); 67 SiteIsolationResponseMetaData();
67 68
68 std::string frame_origin; 69 std::string frame_origin;
69 GURL response_url; 70 GURL response_url;
70 ResourceType resource_type; 71 ResourceType resource_type;
71 CanonicalMimeType canonical_mime_type; 72 CanonicalMimeType canonical_mime_type;
72 int http_status_code; 73 int http_status_code;
73 bool no_sniff; 74 bool no_sniff;
74 }; 75 };
75 76
76 class CONTENT_EXPORT SiteIsolationPolicy { 77 // TODO(nick): Move this class into its own file.
78 class CONTENT_EXPORT SiteIsolationStatsGatherer {
77 public: 79 public:
78 // Set activation flag for the UMA data collection for this renderer process. 80 // Set activation flag for the UMA data collection for this renderer process.
79 static void SetPolicyEnabled(bool enabled); 81 static void SetEnabled(bool enabled);
80 82
81 // Returns any bookkeeping data about the HTTP header information for the 83 // Returns any bookkeeping data about the HTTP header information for the
82 // request identified by |request_id|. Any data returned should then be 84 // request identified by |request_id|. Any data returned should then be
alexmos 2015/06/11 20:17:48 nit: there's no request_id passed to this function
ncarter (slow) 2015/06/16 20:51:13 Done.
83 // passed to OnReceivedFirstChunk() with the first data chunk. 85 // passed to OnReceivedFirstChunk() with the first data chunk.
84 static linked_ptr<SiteIsolationResponseMetaData> OnReceivedResponse( 86 static linked_ptr<SiteIsolationResponseMetaData> OnReceivedResponse(
85 const GURL& frame_origin, 87 const GURL& frame_origin,
86 const GURL& response_url, 88 const GURL& response_url,
87 ResourceType resource_type, 89 ResourceType resource_type,
88 int origin_pid, 90 int origin_pid,
89 const ResourceResponseInfo& info); 91 const ResourceResponseInfo& info);
90 92
91 // Examines the first chunk of network data in case response_url is registered 93 // Examines the first chunk of network data in case response_url is registered
92 // as a cross-site document by DidReceiveResponse(). This records various 94 // as a cross-site document by OnReceivedResponse(). This records various
93 // kinds of UMA data stats. This function is called only if the length of 95 // kinds of UMA data stats. This function is called only if the length of
94 // received data is non-zero. 96 // received data is non-zero.
95 static bool OnReceivedFirstChunk( 97 static bool OnReceivedFirstChunk(
96 const linked_ptr<SiteIsolationResponseMetaData>& resp_data, 98 const linked_ptr<SiteIsolationResponseMetaData>& resp_data,
97 const char* payload, 99 const char* payload,
98 int length); 100 int length);
101 private:
alexmos 2015/06/11 20:17:48 nit: blank line before private:?
ncarter (slow) 2015/06/16 20:51:13 Done.
102 FRIEND_TEST_ALL_PREFIXES(SiteIsolationStatsGathererTest, SniffForJS);
99 103
100 private: 104 SiteIsolationStatsGatherer(); // Not instantiable.
101 FRIEND_TEST_ALL_PREFIXES(SiteIsolationPolicyTest, IsBlockableScheme);
102 FRIEND_TEST_ALL_PREFIXES(SiteIsolationPolicyTest, IsSameSite);
103 FRIEND_TEST_ALL_PREFIXES(SiteIsolationPolicyTest, IsValidCorsHeaderSet);
104 FRIEND_TEST_ALL_PREFIXES(SiteIsolationPolicyTest, SniffForHTML);
105 FRIEND_TEST_ALL_PREFIXES(SiteIsolationPolicyTest, SniffForXML);
106 FRIEND_TEST_ALL_PREFIXES(SiteIsolationPolicyTest, SniffForJSON);
107 FRIEND_TEST_ALL_PREFIXES(SiteIsolationPolicyTest, SniffForJS);
108 105
106 // Imprecise JS sniffing; only appropriate for collecting UMA stat.
107 static bool SniffForJS(base::StringPiece data);
108
109 DISALLOW_COPY_AND_ASSIGN(SiteIsolationStatsGatherer);
110 };
111
112 // TODO(nick): Move this class into its own file.
113 class CONTENT_EXPORT CrossSiteDocumentClassifier {
114 public:
109 // Returns the representative mime type enum value of the mime type of 115 // Returns the representative mime type enum value of the mime type of
110 // response. For example, this returns the same value for all text/xml mime 116 // response. For example, this returns the same value for all text/xml mime
111 // type families such as application/xml, application/rss+xml. 117 // type families such as application/xml, application/rss+xml.
112 static SiteIsolationResponseMetaData::CanonicalMimeType GetCanonicalMimeType( 118 static SiteIsolationResponseMetaData::CanonicalMimeType GetCanonicalMimeType(
113 const std::string& mime_type); 119 const std::string& mime_type);
114 120
115 // Returns whether this scheme is a target of cross-site document 121 // Returns whether this scheme is a target of cross-site document
116 // policy(XSDP). This returns true only for http://* and https://* urls. 122 // policy(XSDP). This returns true only for http://* and https://* urls.
117 static bool IsBlockableScheme(const GURL& frame_origin); 123 static bool IsBlockableScheme(const GURL& frame_origin);
118 124
119 // Returns whether the two urls belong to the same sites. 125 // Returns whether the two urls belong to the same sites.
120 static bool IsSameSite(const GURL& frame_origin, const GURL& response_url); 126 static bool IsSameSite(const GURL& frame_origin, const GURL& response_url);
121 127
122 // Returns whether there's a valid CORS header for frame_origin. This is 128 // Returns whether there's a valid CORS header for frame_origin. This is
123 // simliar to CrossOriginAccessControl::passesAccessControlCheck(), but we use 129 // simliar to CrossOriginAccessControl::passesAccessControlCheck(), but we use
124 // sites as our security domain, not origins. 130 // sites as our security domain, not origins.
125 // TODO(dsjang): this must be improved to be more accurate to the actual CORS 131 // TODO(dsjang): this must be improved to be more accurate to the actual CORS
126 // specification. For now, this works conservatively, allowing XSDs that are 132 // specification. For now, this works conservatively, allowing XSDs that are
127 // not allowed by actual CORS rules by ignoring 1) credentials and 2) 133 // not allowed by actual CORS rules by ignoring 1) credentials and 2)
128 // methods. Preflight requests don't matter here since they are not used to 134 // methods. Preflight requests don't matter here since they are not used to
129 // decide whether to block a document or not on the client side. 135 // decide whether to block a document or not on the client side.
130 static bool IsValidCorsHeaderSet(const GURL& frame_origin, 136 static bool IsValidCorsHeaderSet(const GURL& frame_origin,
131 const GURL& website_origin, 137 const GURL& website_origin,
132 const std::string& access_control_origin); 138 const std::string& access_control_origin);
133 139
134 static bool SniffForHTML(base::StringPiece data); 140 static bool SniffForHTML(base::StringPiece data);
135 static bool SniffForXML(base::StringPiece data); 141 static bool SniffForXML(base::StringPiece data);
136 static bool SniffForJSON(base::StringPiece data); 142 static bool SniffForJSON(base::StringPiece data);
137 143
138 // TODO(dsjang): this is only needed for collecting UMA stat. Will be deleted 144 private:
139 // when this class is used for actual blocking. 145 CrossSiteDocumentClassifier(); // Not instantiable.
140 static bool SniffForJS(base::StringPiece data);
141 146
142 // Never needs to be constructed/destructed. 147 DISALLOW_COPY_AND_ASSIGN(CrossSiteDocumentClassifier);
143 SiteIsolationPolicy() {}
144 ~SiteIsolationPolicy() {}
145
146 DISALLOW_COPY_AND_ASSIGN(SiteIsolationPolicy);
147 }; 148 };
148 149
149 } // namespace content 150 } // namespace content
150 151
151 #endif // CONTENT_CHILD_SITE_ISOLATION_POLICY_H_ 152 #endif // CONTENT_CHILD_SITE_ISOLATION_POLICY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698