Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Properly check the user's cookie settings.
Browse files Browse the repository at this point in the history
NOTE: this commit also removes the `RequestFileSystemAccess` calls which I don't feel are necessary at the moment

Auditors: @darkdh, @bridiver, @diracdeltas
  • Loading branch information
bsclifton committed Jul 6, 2018
1 parent 7d366eb commit 018ecde
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 42 deletions.
44 changes: 10 additions & 34 deletions brave/browser/renderer_host/brave_render_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#include "base/logging.h"
#include "base/macros.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/render_messages.h"
#include "components/content_settings/core/browser/cookie_settings.h"

using content::BrowserThread;

Expand All @@ -32,7 +33,8 @@ BraveRenderMessageFilter::BraveRenderMessageFilter(int render_process_id,
: BrowserMessageFilter(kRenderFilteredMessageClasses,
arraysize(kRenderFilteredMessageClasses)),
render_process_id_(render_process_id),
profile_(profile) {
profile_(profile),
cookie_settings_(CookieSettingsFactory::GetForProfile(profile)) {
}

BraveRenderMessageFilter::~BraveRenderMessageFilter() {
Expand All @@ -43,11 +45,6 @@ bool BraveRenderMessageFilter::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(BraveRenderMessageFilter, message)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowDatabase, OnAllowDatabase)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowDOMStorage, OnAllowDOMStorage)
IPC_MESSAGE_HANDLER_DELAY_REPLY(
ChromeViewHostMsg_RequestFileSystemAccessSync,
OnRequestFileSystemAccessSync)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RequestFileSystemAccessAsync,
OnRequestFileSystemAccessAsync)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowIndexedDB, OnAllowIndexedDB)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
Expand All @@ -62,46 +59,25 @@ void BraveRenderMessageFilter::OnAllowDatabase(
const base::string16& name,
const base::string16& display_name,
bool* allowed) {
*allowed = true;
*allowed =
cookie_settings_->IsCookieAccessAllowed(origin_url, top_origin_url);
}

void BraveRenderMessageFilter::OnAllowDOMStorage(int render_frame_id,
const GURL& origin_url,
const GURL& top_origin_url,
bool local,
bool* allowed) {
*allowed = true;
}

void BraveRenderMessageFilter::OnRequestFileSystemAccessSync(
int render_frame_id,
const GURL& origin_url,
const GURL& top_origin_url,
IPC::Message* reply_msg) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);


ChromeViewHostMsg_RequestFileSystemAccessSync::WriteReplyParams(reply_msg,
true);
Send(reply_msg);
}

void BraveRenderMessageFilter::OnRequestFileSystemAccessAsync(
int render_frame_id,
int request_id,
const GURL& origin_url,
const GURL& top_origin_url) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

Send(new ChromeViewMsg_RequestFileSystemAccessAsyncResponse(
render_frame_id, request_id, true));
*allowed =
cookie_settings_->IsCookieAccessAllowed(origin_url, top_origin_url);
}

void BraveRenderMessageFilter::OnAllowIndexedDB(int render_frame_id,
const GURL& origin_url,
const GURL& top_origin_url,
const base::string16& name,
bool* allowed) {
*allowed = true;
*allowed =
cookie_settings_->IsCookieAccessAllowed(origin_url, top_origin_url);
}

15 changes: 7 additions & 8 deletions brave/browser/renderer_host/brave_render_message_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
class GURL;
class Profile;

namespace content_settings {
class CookieSettings;
}

// This class filters out incoming Chrome-specific IPC messages for the renderer
// process on the IPC thread.
class BraveRenderMessageFilter : public content::BrowserMessageFilter {
Expand All @@ -44,14 +48,6 @@ class BraveRenderMessageFilter : public content::BrowserMessageFilter {
const GURL& top_origin_url,
bool local,
bool* allowed);
void OnRequestFileSystemAccessSync(int render_frame_id,
const GURL& origin_url,
const GURL& top_origin_url,
IPC::Message* message);
void OnRequestFileSystemAccessAsync(int render_frame_id,
int request_id,
const GURL& origin_url,
const GURL& top_origin_url);
void OnAllowIndexedDB(int render_frame_id,
const GURL& origin_url,
const GURL& top_origin_url,
Expand All @@ -64,6 +60,9 @@ class BraveRenderMessageFilter : public content::BrowserMessageFilter {
// accessed on the UI thread!
Profile* profile_;

// Used to look up permissions at database creation time.
scoped_refptr<content_settings::CookieSettings> cookie_settings_;

DISALLOW_COPY_AND_ASSIGN(BraveRenderMessageFilter);
};

Expand Down

0 comments on commit 018ecde

Please sign in to comment.