blob: e32ee52f113e5dfa45a3562f8470a7e18755a7d0 [file] [log] [blame]
nicke7cd12a2015-06-17 06:48:381// 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.
4
5#ifndef CONTENT_COMMON_CROSS_SITE_DOCUMENT_CLASSIFIER_H_
6#define CONTENT_COMMON_CROSS_SITE_DOCUMENT_CLASSIFIER_H_
7
avia9aa7a82015-12-25 03:06:318#include "base/macros.h"
nicke7cd12a2015-06-17 06:48:389#include "base/strings/string_piece.h"
10#include "content/common/content_export.h"
11#include "url/gurl.h"
12
13namespace content {
14
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.
19
20enum 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,
28};
29
30class 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);
37
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);
41
42 // Returns whether the two urls belong to the same sites.
43 static bool IsSameSite(const GURL& frame_origin, const GURL& response_url);
44
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);
56
57 static bool SniffForHTML(base::StringPiece data);
58 static bool SniffForXML(base::StringPiece data);
59 static bool SniffForJSON(base::StringPiece data);
60
61 private:
62 CrossSiteDocumentClassifier(); // Not instantiable.
63
64 DISALLOW_COPY_AND_ASSIGN(CrossSiteDocumentClassifier);
65};
66
67} // namespace content
68
69#endif // CONTENT_COMMON_CROSS_SITE_DOCUMENT_CLASSIFIER_H_