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

Unified Diff: content/browser/web_contents/web_contents_impl.cc

Issue 1832913003: Don't focus the location bar in a phishy situation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Created 4 years, 9 months 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
« no previous file with comments | « chrome/browser/ui/browser_focus_uitest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/web_contents/web_contents_impl.cc
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 0cf85122d7f2c48b961c55a0210ca582b27f9d80..26f3e77dce7de2a9206fce05366a0f648531c4dd 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -2923,9 +2923,28 @@ void WebContentsImpl::ResumeLoadingCreatedWebContents() {
}
bool WebContentsImpl::FocusLocationBarByDefault() {
- NavigationEntry* entry = controller_.GetVisibleEntry();
- if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
+ // When the browser is started with about:blank as the startup URL, focus
+ // the location bar (which will also select its contents) so people can
+ // simply begin typing to navigate elsewhere.
+ //
+ // We need to be careful not to trigger this for anything other than the
+ // startup navigation. In particular, if we allow an attacker to open a
+ // popup to about:blank, then navigate, focusing the Omnibox will cause the
+ // end of the new URL to be scrolled into view instead of the start,
+ // allowing the attacker to spoof other URLs. The conditions checked here
+ // are all aimed at ensuring no such attacker-controlled navigation can
+ // trigger this.
+ //
+ // Note that we check the pending entry instead of the visible one; for the
+ // startup URL case these are the same, but for the attacker-controlled
+ // navigation case the visible entry is the committed "about:blank" URL and
+ // the pending entry is the problematic navigation elsewhere.
+ NavigationEntryImpl* entry = controller_.GetPendingEntry();
+ if (controller_.IsInitialNavigation() && entry &&
+ !entry->is_renderer_initiated() &&
+ entry->GetURL() == GURL(url::kAboutBlankURL)) {
return true;
+ }
return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
}
« no previous file with comments | « chrome/browser/ui/browser_focus_uitest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698