Commit 8dcfbfdc authored by jochen's avatar jochen Committed by Commit bot

Sanitize referrers before we create them

Unless we reconstruct an already sanitized referrer from the referrer
url and the referrer policy, we should always sanitize it before
constructing a request from it.

BUG=454621,422871
R=mkwst@chromium.org,jam@chromium.org

Review URL: https://codereview.chromium.org/898613004

Cr-Commit-Position: refs/heads/master@{#315360}
parent 2567caca
...@@ -80,7 +80,8 @@ void UnregisterAndReplaceOverrideForWebContents(const std::string& page, ...@@ -80,7 +80,8 @@ void UnregisterAndReplaceOverrideForWebContents(const std::string& page,
// Don't use Reload() since |url| isn't the same as the internal URL that // Don't use Reload() since |url| isn't the same as the internal URL that
// NavigationController has. // NavigationController has.
web_contents->GetController().LoadURL( web_contents->GetController().LoadURL(
url, content::Referrer(url, blink::WebReferrerPolicyDefault), url, content::Referrer::SanitizeForRequest(
url, content::Referrer(url, blink::WebReferrerPolicyDefault)),
ui::PAGE_TRANSITION_RELOAD, std::string()); ui::PAGE_TRANSITION_RELOAD, std::string());
} }
......
...@@ -142,12 +142,13 @@ bool WebstoreInlineInstaller::CheckInlineInstallPermitted( ...@@ -142,12 +142,13 @@ bool WebstoreInlineInstaller::CheckInlineInstallPermitted(
*error = kInvalidWebstoreResponseError; *error = kInvalidWebstoreResponseError;
return false; return false;
} }
web_contents()->OpenURL( web_contents()->OpenURL(content::OpenURLParams(
content::OpenURLParams( GURL(redirect_url),
content::Referrer::SanitizeForRequest(
GURL(redirect_url), GURL(redirect_url),
content::Referrer(web_contents()->GetURL(), content::Referrer(web_contents()->GetURL(),
blink::WebReferrerPolicyDefault), blink::WebReferrerPolicyDefault)),
NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_BOOKMARK, false)); NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_BOOKMARK, false));
*error = kInlineInstallSupportedError; *error = kInlineInstallSupportedError;
return false; return false;
} }
......
...@@ -649,9 +649,9 @@ void WebstoreInstaller::StartDownload(const std::string& extension_id, ...@@ -649,9 +649,9 @@ void WebstoreInstaller::StartDownload(const std::string& extension_id,
resource_context)); resource_context));
params->set_file_path(file); params->set_file_path(file);
if (controller.GetVisibleEntry()) if (controller.GetVisibleEntry())
params->set_referrer( params->set_referrer(content::Referrer::SanitizeForRequest(
content::Referrer(controller.GetVisibleEntry()->GetURL(), download_url_, content::Referrer(controller.GetVisibleEntry()->GetURL(),
blink::WebReferrerPolicyDefault)); blink::WebReferrerPolicyDefault)));
params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted,
this, this,
extension_id)); extension_id));
......
...@@ -441,8 +441,10 @@ void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) { ...@@ -441,8 +441,10 @@ void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) {
void PluginObserver::OnOpenAboutPlugins() { void PluginObserver::OnOpenAboutPlugins() {
web_contents()->OpenURL(OpenURLParams( web_contents()->OpenURL(OpenURLParams(
GURL(chrome::kChromeUIPluginsURL), GURL(chrome::kChromeUIPluginsURL),
content::Referrer(web_contents()->GetURL(), content::Referrer::SanitizeForRequest(
blink::WebReferrerPolicyDefault), GURL(chrome::kChromeUIPluginsURL),
content::Referrer(web_contents()->GetURL(),
blink::WebReferrerPolicyDefault)),
NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_BOOKMARK, false)); NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_BOOKMARK, false));
} }
......
...@@ -262,10 +262,10 @@ WebContents* OpenApplicationTab(const AppLaunchParams& launch_params, ...@@ -262,10 +262,10 @@ WebContents* OpenApplicationTab(const AppLaunchParams& launch_params,
int tab_index = model->GetIndexOfWebContents(existing_tab); int tab_index = model->GetIndexOfWebContents(existing_tab);
existing_tab->OpenURL(content::OpenURLParams( existing_tab->OpenURL(content::OpenURLParams(
url, url, content::Referrer::SanitizeForRequest(
content::Referrer(existing_tab->GetURL(), url, content::Referrer(existing_tab->GetURL(),
blink::WebReferrerPolicyDefault), blink::WebReferrerPolicyDefault)),
disposition, ui::PAGE_TRANSITION_LINK, false)); disposition, ui::PAGE_TRANSITION_LINK, false));
// Reset existing_tab as OpenURL() may have clobbered it. // Reset existing_tab as OpenURL() may have clobbered it.
existing_tab = browser->tab_strip_model()->GetActiveWebContents(); existing_tab = browser->tab_strip_model()->GetActiveWebContents();
if (params.tabstrip_add_types & TabStripModel::ADD_PINNED) { if (params.tabstrip_add_types & TabStripModel::ADD_PINNED) {
......
...@@ -140,8 +140,9 @@ void PrerenderDispatcher::add(const WebPrerender& prerender) { ...@@ -140,8 +140,9 @@ void PrerenderDispatcher::add(const WebPrerender& prerender) {
content::RenderThread::Get()->Send(new PrerenderHostMsg_AddLinkRelPrerender( content::RenderThread::Get()->Send(new PrerenderHostMsg_AddLinkRelPrerender(
extra_data.prerender_id(), attributes, extra_data.prerender_id(), attributes,
content::Referrer(GURL(prerender.referrer()), content::Referrer::SanitizeForRequest(
prerender.referrerPolicy()), GURL(prerender.url()), content::Referrer(GURL(prerender.referrer()),
prerender.referrerPolicy())),
extra_data.size(), extra_data.render_view_route_id())); extra_data.size(), extra_data.render_view_route_id()));
} }
......
...@@ -117,7 +117,9 @@ bool InterceptNavigationResourceThrottle::CheckIfShouldIgnoreNavigation( ...@@ -117,7 +117,9 @@ bool InterceptNavigationResourceThrottle::CheckIfShouldIgnoreNavigation(
!info->GetContext()->GetRequestContext()->job_factory()->IsHandledURL( !info->GetContext()->GetRequestContext()->job_factory()->IsHandledURL(
url); url);
NavigationParams navigation_params( NavigationParams navigation_params(
url, Referrer(GURL(request_->referrer()), info->GetReferrerPolicy()), url,
Referrer::SanitizeForRequest(
url, Referrer(GURL(request_->referrer()), info->GetReferrerPolicy())),
info->HasUserGesture(), method == "POST", info->GetPageTransition(), info->HasUserGesture(), method == "POST", info->GetPageTransition(),
is_redirect, is_external_protocol); is_redirect, is_external_protocol);
......
...@@ -153,8 +153,9 @@ int32_t PepperPDFHost::OnHostMsgSaveAs( ...@@ -153,8 +153,9 @@ int32_t PepperPDFHost::OnHostMsgSaveAs(
content::RenderView* render_view = instance->GetRenderView(); content::RenderView* render_view = instance->GetRenderView();
blink::WebLocalFrame* frame = blink::WebLocalFrame* frame =
render_view->GetWebView()->mainFrame()->toWebLocalFrame(); render_view->GetWebView()->mainFrame()->toWebLocalFrame();
content::Referrer referrer(frame->document().url(), content::Referrer referrer = content::Referrer::SanitizeForRequest(
frame->document().referrerPolicy()); url, content::Referrer(frame->document().url(),
frame->document().referrerPolicy()));
render_view->Send( render_view->Send(
new PDFHostMsg_PDFSaveURLAs(render_view->GetRoutingID(), url, referrer)); new PDFHostMsg_PDFSaveURLAs(render_view->GetRoutingID(), url, referrer));
return PP_OK; return PP_OK;
......
...@@ -242,8 +242,9 @@ void SaveAs(PP_Instance instance_id) { ...@@ -242,8 +242,9 @@ void SaveAs(PP_Instance instance_id) {
content::RenderView* render_view = instance->GetRenderView(); content::RenderView* render_view = instance->GetRenderView();
blink::WebLocalFrame* frame = blink::WebLocalFrame* frame =
render_view->GetWebView()->mainFrame()->toWebLocalFrame(); render_view->GetWebView()->mainFrame()->toWebLocalFrame();
content::Referrer referrer(frame->document().url(), content::Referrer referrer = content::Referrer::SanitizeForRequest(
frame->document().referrerPolicy()); url, content::Referrer(frame->document().url(),
frame->document().referrerPolicy()));
render_view->Send( render_view->Send(
new PDFHostMsg_PDFSaveURLAs(render_view->GetRoutingID(), url, referrer)); new PDFHostMsg_PDFSaveURLAs(render_view->GetRoutingID(), url, referrer));
} }
......
...@@ -57,14 +57,14 @@ ContentSerializedNavigationBuilder::ToNavigationEntry( ...@@ -57,14 +57,14 @@ ContentSerializedNavigationBuilder::ToNavigationEntry(
scoped_ptr<content::NavigationEntry> entry( scoped_ptr<content::NavigationEntry> entry(
content::NavigationController::CreateNavigationEntry( content::NavigationController::CreateNavigationEntry(
navigation->virtual_url_, navigation->virtual_url_,
content::Referrer(navigation->referrer_url_, policy), content::Referrer::SanitizeForRequest(
navigation->virtual_url_,
content::Referrer(navigation->referrer_url_, policy)),
// Use a transition type of reload so that we don't incorrectly // Use a transition type of reload so that we don't incorrectly
// increase the typed count. // increase the typed count.
ui::PAGE_TRANSITION_RELOAD, ui::PAGE_TRANSITION_RELOAD, false,
false,
// The extra headers are not sync'ed across sessions. // The extra headers are not sync'ed across sessions.
std::string(), std::string(), browser_context));
browser_context));
entry->SetTitle(navigation->title_); entry->SetTitle(navigation->title_);
entry->SetPageState(content::PageState::CreateFromEncodedData( entry->SetPageState(content::PageState::CreateFromEncodedData(
......
...@@ -299,8 +299,8 @@ void IndexedDBInternalsUI::OnDownloadDataReady( ...@@ -299,8 +299,8 @@ void IndexedDBInternalsUI::OnDownloadDataReady(
DownloadManager* dlm = BrowserContext::GetDownloadManager(browser_context); DownloadManager* dlm = BrowserContext::GetDownloadManager(browser_context);
const GURL referrer(web_ui()->GetWebContents()->GetLastCommittedURL()); const GURL referrer(web_ui()->GetWebContents()->GetLastCommittedURL());
dl_params->set_referrer( dl_params->set_referrer(content::Referrer::SanitizeForRequest(
content::Referrer(referrer, blink::WebReferrerPolicyDefault)); url, content::Referrer(referrer, blink::WebReferrerPolicyDefault)));
// This is how to watch for the download to finish: first wait for it // This is how to watch for the download to finish: first wait for it
// to start, then attach a DownloadItem::Observer to observe the // to start, then attach a DownloadItem::Observer to observe the
......
...@@ -244,11 +244,11 @@ void OpenWindowOnUI( ...@@ -244,11 +244,11 @@ void OpenWindowOnUI(
return; return;
} }
OpenURLParams params(url, OpenURLParams params(
Referrer(script_url, blink::WebReferrerPolicyDefault), url, Referrer::SanitizeForRequest(
NEW_FOREGROUND_TAB, url, Referrer(script_url, blink::WebReferrerPolicyDefault)),
ui::PAGE_TRANSITION_AUTO_TOPLEVEL, NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
true /* is_renderer_initiated */); true /* is_renderer_initiated */);
WebContents* web_contents = WebContents* web_contents =
GetContentClient()->browser()->OpenURL(browser_context, params); GetContentClient()->browser()->OpenURL(browser_context, params);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment