Update V8 to version 4.7.42.
[chromium-blink-merge.git] / content / common / cross_site_document_classifier.h
blob5f20463518c7154fdf405c736237fde8f83e4f41
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_CROSS_SITE_DOCUMENT_CLASSIFIER_H_
6 #define CONTENT_COMMON_CROSS_SITE_DOCUMENT_CLASSIFIER_H_
8 #include "base/basictypes.h"
9 #include "base/strings/string_piece.h"
10 #include "content/common/content_export.h"
11 #include "url/gurl.h"
13 namespace content {
15 // CrossSiteDocumentClassifier implements the cross-site document blocking
16 // policy (XSDP) for Site Isolation. XSDP will monitor network responses to a
17 // renderer and block illegal responses so that a compromised renderer cannot
18 // steal private information from other sites.
20 enum CrossSiteDocumentMimeType {
21 // Note that these values are used in histograms, and must not change.
22 CROSS_SITE_DOCUMENT_MIME_TYPE_HTML = 0,
23 CROSS_SITE_DOCUMENT_MIME_TYPE_XML = 1,
24 CROSS_SITE_DOCUMENT_MIME_TYPE_JSON = 2,
25 CROSS_SITE_DOCUMENT_MIME_TYPE_PLAIN = 3,
26 CROSS_SITE_DOCUMENT_MIME_TYPE_OTHERS = 4,
27 CROSS_SITE_DOCUMENT_MIME_TYPE_MAX,
30 class CONTENT_EXPORT CrossSiteDocumentClassifier {
31 public:
32 // Returns the representative mime type enum value of the mime type of
33 // response. For example, this returns the same value for all text/xml mime
34 // type families such as application/xml, application/rss+xml.
35 static CrossSiteDocumentMimeType GetCanonicalMimeType(
36 const std::string& mime_type);
38 // Returns whether this scheme is a target of cross-site document
39 // policy(XSDP). This returns true only for http://* and https://* urls.
40 static bool IsBlockableScheme(const GURL& frame_origin);
42 // Returns whether the two urls belong to the same sites.
43 static bool IsSameSite(const GURL& frame_origin, const GURL& response_url);
45 // Returns whether there's a valid CORS header for frame_origin. This is
46 // simliar to CrossOriginAccessControl::passesAccessControlCheck(), but we use
47 // sites as our security domain, not origins.
48 // TODO(dsjang): this must be improved to be more accurate to the actual CORS
49 // specification. For now, this works conservatively, allowing XSDs that are
50 // not allowed by actual CORS rules by ignoring 1) credentials and 2)
51 // methods. Preflight requests don't matter here since they are not used to
52 // decide whether to block a document or not on the client side.
53 static bool IsValidCorsHeaderSet(const GURL& frame_origin,
54 const GURL& website_origin,
55 const std::string& access_control_origin);
57 static bool SniffForHTML(base::StringPiece data);
58 static bool SniffForXML(base::StringPiece data);
59 static bool SniffForJSON(base::StringPiece data);
61 private:
62 CrossSiteDocumentClassifier(); // Not instantiable.
64 DISALLOW_COPY_AND_ASSIGN(CrossSiteDocumentClassifier);
67 } // namespace content
69 #endif // CONTENT_COMMON_CROSS_SITE_DOCUMENT_CLASSIFIER_H_