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

Unified Diff: chrome/browser/security/xfo_throttle.cc

Issue 1530393003: WIP: Move 'X-Frame-Options' checking to the browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/security/xfo_throttle.cc
diff --git a/chrome/browser/security/xfo_throttle.cc b/chrome/browser/security/xfo_throttle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a1c459fb9004a7c0a28b2767cf35fe6a5e16f7b9
--- /dev/null
+++ b/chrome/browser/security/xfo_throttle.cc
@@ -0,0 +1,73 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/security/xfo_throttle.h"
+
+#include "base/strings/string_util.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/navigation_throttle.h"
+#include "net/http/http_response_headers.h"
+
+// static
+scoped_ptr<NavigationThrottle> XFOThrottle::MaybeCreateThrottleFor(
+ NavigationHandle* handle) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+
+ if (handle->IsInMainFrame())
+ return nullptr;
+
+ return scoped_ptr<NavigationThrottle>(new XFOThrottle(handle));
+}
+
+XFOThrottle::XFOThrottle(NavigationHandle* handle)
+ : NavigationThrottle(handle) {}
+
+XFOThrottle::~XFOThrottle() {}
+
+NavigationThrottle::ThrottleCheckResult XFOThrottle::WillProcessResponse() {
+ DCHECK(!navigation_handle()->IsInMainFrame());
+
+ HeaderDisposition disposition =
+ ParseHeader(navigation_handle()->GetResponseHeaders());
+ switch (disposition) {
+ case DENY:
+ case CONFLICT:
+ case INVALID:
+ return NavigationThrottle::CANCEL_AND_IGNORE;
+
Mike West 2015/12/17 13:37:54 Here, I need to grab the frame tree in order to ch
clamy 2015/12/21 10:13:29 I think you should move this to content/ (the fram
+ default:
+ return NavigationThrottle::PROCEED;
+ }
+ return NavigationThrottle::PROCEED;
+}
+
+XFOThrottle::HeaderDisposition XFOThrottle::ParseHeader(
+ const net::HttpResponseHeaders* headers) {
+ if (!headers)
+ return NOT_PRESENT;
+
+ void* iter = nullptr;
+ std::string value;
+ HeaderDisposition result = NOT_PRESENT;
+ while (headers->EnumerateHeader(&iter, "x-frame-options", &value)) {
+ HeaderDisposition current = INVALID;
+ base::StringPiece trimmed =
+ base::TrimWhitespaceASCII(value, base::TRIM_ALL);
+ if (base::LowerCaseEqualsASCII(trimmed, "deny"))
+ current = DENY;
+ else if (base::LowerCaseEqualsASCII(trimmed, "allowall"))
+ current = ALLOWALL;
+ else if (base::LowerCaseEqualsASCII(trimmed, "sameorigin"))
+ current = SAMEORIGIN;
+
+ if (result == NOT_PRESENT)
+ result = current;
+ else if (result == current)
+ continue;
+ else
+ return CONFLICT;
+ }
+ return result;
+}

Powered by Google App Engine
This is Rietveld 408576698