Skip to content

Commit

Permalink
fix: extend content layer hook to bypass corb when web security is di…
Browse files Browse the repository at this point in the history
…sabled.
  • Loading branch information
deepak1556 committed Nov 21, 2018
1 parent 65099ab commit b2e9e2a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions atom/browser/atom_browser_client.cc
Expand Up @@ -223,28 +223,34 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance(
void AtomBrowserClient::AddProcessPreferences(
int process_id,
AtomBrowserClient::ProcessPreferences prefs) {
base::AutoLock auto_lock(process_preferences_lock_);
process_preferences_[process_id] = prefs;
}

void AtomBrowserClient::RemoveProcessPreferences(int process_id) {
base::AutoLock auto_lock(process_preferences_lock_);
process_preferences_.erase(process_id);
}

bool AtomBrowserClient::IsProcessObserved(int process_id) {
base::AutoLock auto_lock(process_preferences_lock_);
return process_preferences_.find(process_id) != process_preferences_.end();
}

bool AtomBrowserClient::IsRendererSandboxed(int process_id) {
base::AutoLock auto_lock(process_preferences_lock_);
auto it = process_preferences_.find(process_id);
return it != process_preferences_.end() && it->second.sandbox;
}

bool AtomBrowserClient::RendererUsesNativeWindowOpen(int process_id) {
base::AutoLock auto_lock(process_preferences_lock_);
auto it = process_preferences_.find(process_id);
return it != process_preferences_.end() && it->second.native_window_open;
}

bool AtomBrowserClient::RendererDisablesPopups(int process_id) {
base::AutoLock auto_lock(process_preferences_lock_);
auto it = process_preferences_.find(process_id);
return it != process_preferences_.end() && it->second.disable_popups;
}
Expand Down Expand Up @@ -274,6 +280,8 @@ void AtomBrowserClient::RenderProcessWillLaunch(
prefs.native_window_open =
web_preferences->IsEnabled(options::kNativeWindowOpen);
prefs.disable_popups = web_preferences->IsEnabled("disablePopups");
prefs.web_security = web_preferences->IsEnabled(options::kWebSecurity,
true /* default value */);
}
AddProcessPreferences(host->GetID(), prefs);
// ensure the ProcessPreferences is removed later
Expand Down Expand Up @@ -778,6 +786,13 @@ void AtomBrowserClient::OnNetworkServiceCreated(
network_service);
}

bool AtomBrowserClient::ShouldBypassCORB(int render_process_id) {
// This is called on the network thread.
base::AutoLock auto_lock(process_preferences_lock_);
auto it = process_preferences_.find(render_process_id);
return it != process_preferences_.end() && !it->second.web_security;
}

std::string AtomBrowserClient::GetApplicationLocale() {
if (BrowserThread::CurrentlyOn(BrowserThread::IO))
return g_io_thread_application_locale.Get();
Expand Down
7 changes: 6 additions & 1 deletion atom/browser/atom_browser_client.h
Expand Up @@ -11,6 +11,7 @@
#include <string>
#include <vector>

#include "base/synchronization/lock.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/render_process_host_observer.h"
#include "net/ssl/client_cert_identity.h"
Expand Down Expand Up @@ -143,6 +144,7 @@ class AtomBrowserClient : public content::ContentBrowserClient,
GetSystemSharedURLLoaderFactory() override;
void OnNetworkServiceCreated(
network::mojom::NetworkService* network_service) override;
bool ShouldBypassCORB(int render_process_id) override;

// content::RenderProcessHostObserver:
void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
Expand All @@ -164,6 +166,7 @@ class AtomBrowserClient : public content::ContentBrowserClient,
bool sandbox = false;
bool native_window_open = false;
bool disable_popups = false;
bool web_security = true;
};

bool ShouldCreateNewSiteInstance(content::RenderFrameHost* render_frame_host,
Expand All @@ -180,7 +183,6 @@ class AtomBrowserClient : public content::ContentBrowserClient,
// pending_render_process => web contents.
std::map<int, content::WebContents*> pending_processes_;

std::map<int, ProcessPreferences> process_preferences_;
std::map<int, base::ProcessId> render_process_host_pids_;

// list of site per affinity. weak_ptr to prevent instance locking
Expand All @@ -194,6 +196,9 @@ class AtomBrowserClient : public content::ContentBrowserClient,

Delegate* delegate_ = nullptr;

base::Lock process_preferences_lock_;
std::map<int, ProcessPreferences> process_preferences_;

DISALLOW_COPY_AND_ASSIGN(AtomBrowserClient);
};

Expand Down

0 comments on commit b2e9e2a

Please sign in to comment.