Commit a4c2a76e authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

[CSP] Stop failing when requesting default favicon.ico

Before fetching the default URL, make sure it won't be blocked by CSP.
The webpage didn't requested "/favicon.ico", it is automatic. Developers
shouldn't suffer from any errors provoked by Chrome.

Fixed: 820846
Bug: 820846
Change-Id: I427bd1bce2230d57339127e8efb6fbe24bb319a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2438388Reviewed-by: default avatarMike West <mkwst@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818404}
parent c40b6f3f
...@@ -5048,4 +5048,29 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -5048,4 +5048,29 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
EXPECT_EQ("POST", root_frame_host()->last_http_method()); EXPECT_EQ("POST", root_frame_host()->last_http_method());
} }
// Check Chrome won't attempt automatically loading the /favicon.ico if it would
// be blocked by CSP.
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
DefaultFaviconVersusCSP) {
auto navigate = [&](std::string csp) {
EXPECT_TRUE(NavigateToURL(
shell(), embedded_test_server()->GetURL(
"/set-header?Content-Security-Policy: " + csp)));
// DidStopLoading() and UpdateFaviconURL() are sent together from the same
// task. However we have waited only for DidStopLoading(). Make a round trip
// with the renderer to ensure UpdateFaviconURL() to be received.
EXPECT_TRUE(ExecJs(root_frame_host(), ""));
};
// Blocked by CSP.
navigate("img-src 'none'");
EXPECT_EQ(0u, web_contents()->GetFaviconURLs().size());
// Allowed by CSP.
navigate("img-src *");
EXPECT_EQ(1u, web_contents()->GetFaviconURLs().size());
EXPECT_EQ("/favicon.ico",
web_contents()->GetFaviconURLs()[0]->icon_url.path());
}
} // namespace content } // namespace content
...@@ -391,6 +391,26 @@ void NotifyPriorityScrollAnchorStatusChanged(Node* first, Node* second) { ...@@ -391,6 +391,26 @@ void NotifyPriorityScrollAnchorStatusChanged(Node* first, Node* second) {
second->NotifyPriorityScrollAnchorStatusChanged(); second->NotifyPriorityScrollAnchorStatusChanged();
} }
// Before fetching the default URL, make sure it won't be blocked by CSP. The
// webpage didn't requested "/favicon.ico", it is automatic. Developers
// shouldn't suffer from any errors provoked by Chrome.
// See https://crbug.com/820846
bool DefaultFaviconAllowedByCSP(const Document* document, const IconURL& icon) {
ExecutionContext* context = document->GetExecutionContext();
if (!context) {
// LocalFrame::UpdateFaviconURL() is sometimes called after a LocalFrame
// swap. When this happens, the document has lost its ExecutionContext and
// the favicon won't be loaded anyway. The output of this function doesn't
// matter anymore.
return false;
}
return context->GetContentSecurityPolicy()->AllowImageFromSource(
icon.icon_url_, icon.icon_url_, RedirectStatus::kNoRedirect,
ReportingDisposition::kSuppressReporting,
ContentSecurityPolicy::CheckHeaderType::kCheckAll);
}
} // namespace } // namespace
class DocumentOutliveTimeReporter : public BlinkGCObserver { class DocumentOutliveTimeReporter : public BlinkGCObserver {
...@@ -7081,7 +7101,9 @@ Vector<IconURL> Document::IconURLs(int icon_types_mask) { ...@@ -7081,7 +7101,9 @@ Vector<IconURL> Document::IconURLs(int icon_types_mask) {
} else if (url_.ProtocolIsInHTTPFamily() && } else if (url_.ProtocolIsInHTTPFamily() &&
icon_types_mask & 1 << static_cast<int>( icon_types_mask & 1 << static_cast<int>(
mojom::blink::FaviconIconType::kFavicon)) { mojom::blink::FaviconIconType::kFavicon)) {
icon_urls.push_back(IconURL::DefaultFavicon(url_)); IconURL default_favicon = IconURL::DefaultFavicon(url_);
if (DefaultFaviconAllowedByCSP(this, default_favicon))
icon_urls.push_back(std::move(default_favicon));
} }
if (first_touch_icon.icon_type_ != mojom::blink::FaviconIconType::kInvalid) if (first_touch_icon.icon_type_ != mojom::blink::FaviconIconType::kInvalid)
......
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