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

Side by Side Diff: content/common/cross_site_document_classifier.h

Issue 1174323002: [Patch 5 of 6] Split out the site_isolation_policy files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rename_policy_to_sniffer3
Patch Set: Pull 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 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_COMMON_CROSS_SITE_DOCUMENT_CLASSIFIER_H_
6 #define CONTENT_CHILD_SITE_ISOLATION_POLICY_H_ 6 #define CONTENT_COMMON_CROSS_SITE_DOCUMENT_CLASSIFIER_H_
7 7
8 #include <map> 8 #include "base/basictypes.h"
9 #include <utility>
10
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/linked_ptr.h"
13 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
14 #include "content/common/content_export.h" 10 #include "content/common/content_export.h"
15 #include "content/public/common/resource_type.h"
16 #include "url/gurl.h" 11 #include "url/gurl.h"
17 12
18 namespace content { 13 namespace content {
19 14
20 struct ResourceResponseInfo;
21
22 // CrossSiteDocumentClassifier implements the cross-site document blocking 15 // CrossSiteDocumentClassifier implements the cross-site document blocking
23 // policy (XSDP) for Site Isolation. XSDP will monitor network responses to a 16 // policy (XSDP) for Site Isolation. XSDP will monitor network responses to a
24 // renderer and block illegal responses so that a compromised renderer cannot 17 // renderer and block illegal responses so that a compromised renderer cannot
25 // steal private information from other sites. 18 // steal private information from other sites.
26 //
27 // SiteIsolationStatsGatherer monitors responses to gather various UMA stats to
28 // see the compatibility impact of actual deployment of the policy. The UMA stat
29 // categories SiteIsolationStatsGatherer gathers are as follows:
30 //
31 // SiteIsolation.AllResponses : # of all network responses.
32 // SiteIsolation.XSD.DataLength : the length of the first packet of a response.
33 // SiteIsolation.XSD.MimeType (enum):
34 // # of responses from other sites, tagged with a document mime type.
35 // 0:HTML, 1:XML, 2:JSON, 3:Plain, 4:Others
36 // SiteIsolation.XSD.[%MIMETYPE].Blocked :
37 // blocked # of cross-site document responses grouped by sniffed MIME type.
38 // SiteIsolation.XSD.[%MIMETYPE].Blocked.RenderableStatusCode :
39 // # of responses with renderable status code,
40 // out of SiteIsolation.XSD.[%MIMETYPE].Blocked.
41 // SiteIsolation.XSD.[%MIMETYPE].Blocked.NonRenderableStatusCode :
42 // # of responses with non-renderable status code,
43 // out of SiteIsolation.XSD.[%MIMETYPE].Blocked.
44 // SiteIsolation.XSD.[%MIMETYPE].NoSniffBlocked.RenderableStatusCode :
45 // # of responses failed to be sniffed for its MIME type, but blocked by
46 // "X-Content-Type-Options: nosniff" header, and with renderable status code
47 // out of SiteIsolation.XSD.[%MIMETYPE].Blocked.
48 // SiteIsolation.XSD.[%MIMETYPE].NoSniffBlocked.NonRenderableStatusCode :
49 // # 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
51 // code out of SiteIsolation.XSD.[%MIMETYPE].Blocked.
52 // SiteIsolation.XSD.[%MIMETYPE].NotBlocked :
53 // # of responses, but not blocked due to failure of mime sniffing.
54 // SiteIsolation.XSD.[%MIMETYPE].NotBlocked.MaybeJS :
55 // # of responses that are plausibly sniffed to be JavaScript.
56 19
57 enum CrossSiteDocumentMimeType { 20 enum CrossSiteDocumentMimeType {
58 // Note that these values are used in histograms, and must not change. 21 // Note that these values are used in histograms, and must not change.
59 CROSS_SITE_DOCUMENT_MIME_TYPE_HTML = 0, 22 CROSS_SITE_DOCUMENT_MIME_TYPE_HTML = 0,
60 CROSS_SITE_DOCUMENT_MIME_TYPE_XML = 1, 23 CROSS_SITE_DOCUMENT_MIME_TYPE_XML = 1,
61 CROSS_SITE_DOCUMENT_MIME_TYPE_JSON = 2, 24 CROSS_SITE_DOCUMENT_MIME_TYPE_JSON = 2,
62 CROSS_SITE_DOCUMENT_MIME_TYPE_PLAIN = 3, 25 CROSS_SITE_DOCUMENT_MIME_TYPE_PLAIN = 3,
63 CROSS_SITE_DOCUMENT_MIME_TYPE_OTHERS = 4, 26 CROSS_SITE_DOCUMENT_MIME_TYPE_OTHERS = 4,
64 CROSS_SITE_DOCUMENT_MIME_TYPE_MAX, 27 CROSS_SITE_DOCUMENT_MIME_TYPE_MAX,
65 }; 28 };
66 29
67 struct SiteIsolationResponseMetaData {
68 SiteIsolationResponseMetaData();
69
70 std::string frame_origin;
71 GURL response_url;
72 ResourceType resource_type;
73 CrossSiteDocumentMimeType canonical_mime_type;
74 int http_status_code;
75 bool no_sniff;
76 };
77
78 // TODO(nick): Move this class into its own file.
79 class CONTENT_EXPORT SiteIsolationStatsGatherer {
80 public:
81 // Set activation flag for the UMA data collection for this renderer process.
82 static void SetEnabled(bool enabled);
83
84 // Returns any bookkeeping data about the HTTP header information for the
85 // request identified by |request_id|. Any data returned should then be
86 // passed to OnReceivedFirstChunk() with the first data chunk.
87 static linked_ptr<SiteIsolationResponseMetaData> OnReceivedResponse(
88 const GURL& frame_origin,
89 const GURL& response_url,
90 ResourceType resource_type,
91 int origin_pid,
92 const ResourceResponseInfo& info);
93
94 // Examines the first chunk of network data in case response_url is registered
95 // as a cross-site document by OnReceivedResponse(). This records various
96 // kinds of UMA data stats. This function is called only if the length of
97 // received data is non-zero.
98 static bool OnReceivedFirstChunk(
99 const linked_ptr<SiteIsolationResponseMetaData>& resp_data,
100 const char* payload,
101 int length);
102 private:
103 FRIEND_TEST_ALL_PREFIXES(SiteIsolationStatsGathererTest, SniffForJS);
104
105 SiteIsolationStatsGatherer(); // Not instantiable.
106
107 // Imprecise JS sniffing; only appropriate for collecting UMA stat.
108 static bool SniffForJS(base::StringPiece data);
109
110 DISALLOW_COPY_AND_ASSIGN(SiteIsolationStatsGatherer);
111 };
112
113 // TODO(nick): Move this class into its own file.
114 class CONTENT_EXPORT CrossSiteDocumentClassifier { 30 class CONTENT_EXPORT CrossSiteDocumentClassifier {
115 public: 31 public:
116 // Returns the representative mime type enum value of the mime type of 32 // 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 33 // response. For example, this returns the same value for all text/xml mime
118 // type families such as application/xml, application/rss+xml. 34 // type families such as application/xml, application/rss+xml.
119 static CrossSiteDocumentMimeType GetCanonicalMimeType( 35 static CrossSiteDocumentMimeType GetCanonicalMimeType(
120 const std::string& mime_type); 36 const std::string& mime_type);
121 37
122 // Returns whether this scheme is a target of cross-site document 38 // Returns whether this scheme is a target of cross-site document
123 // policy(XSDP). This returns true only for http://* and https://* urls. 39 // policy(XSDP). This returns true only for http://* and https://* urls.
(...skipping 19 matching lines...) Expand all
143 static bool SniffForJSON(base::StringPiece data); 59 static bool SniffForJSON(base::StringPiece data);
144 60
145 private: 61 private:
146 CrossSiteDocumentClassifier(); // Not instantiable. 62 CrossSiteDocumentClassifier(); // Not instantiable.
147 63
148 DISALLOW_COPY_AND_ASSIGN(CrossSiteDocumentClassifier); 64 DISALLOW_COPY_AND_ASSIGN(CrossSiteDocumentClassifier);
149 }; 65 };
150 66
151 } // namespace content 67 } // namespace content
152 68
153 #endif // CONTENT_CHILD_SITE_ISOLATION_POLICY_H_ 69 #endif // CONTENT_COMMON_CROSS_SITE_DOCUMENT_CLASSIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698