Commit 171aff9f authored by Oleh Lamzin's avatar Oleh Lamzin Committed by Commit Bot

Respect FrameSrc directive in WebUI

Respect FrameSrc directive in WebUI, otherwise WebUIs use wider
ChildSrc CSP to be able to embed iframes.

In many places we are using 'frame-src' CSP with ChildSrc directive
which is wrong. We have to either use 'frame-src' with FrameSrc or
'child-src' with ChildSrc. Mostly we just need to be able to embed
iframe and do not need web workers, so 'frame-src' will be enough.

Bug: 1105408
Change-Id: I6d7bd555f6411971db24fdfe9e3f299bf83a8a0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2302990Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Commit-Queue: Oleh Lamzin <lamzin@google.com>
Cr-Commit-Position: refs/heads/master@{#789399}
parent 7a671fe2
...@@ -53,7 +53,7 @@ HelpAppUI::HelpAppUI(content::WebUI* web_ui, ...@@ -53,7 +53,7 @@ HelpAppUI::HelpAppUI(content::WebUI* web_ui,
std::string csp = std::string csp =
std::string("frame-src ") + kChromeUIHelpAppUntrustedURL + ";"; std::string("frame-src ") + kChromeUIHelpAppUntrustedURL + ";";
host_source->OverrideContentSecurityPolicy( host_source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ChildSrc, csp); network::mojom::CSPDirectiveName::FrameSrc, csp);
content::WebUIDataSource* untrusted_source = content::WebUIDataSource* untrusted_source =
CreateHelpAppUntrustedDataSource(delegate_.get()); CreateHelpAppUntrustedDataSource(delegate_.get());
......
...@@ -62,7 +62,7 @@ MediaAppUI::MediaAppUI(content::WebUI* web_ui, ...@@ -62,7 +62,7 @@ MediaAppUI::MediaAppUI(content::WebUI* web_ui,
// The guest is in an <iframe>. Add it to CSP. // The guest is in an <iframe>. Add it to CSP.
std::string csp = std::string("frame-src ") + kChromeUIMediaAppGuestURL + ";"; std::string csp = std::string("frame-src ") + kChromeUIMediaAppGuestURL + ";";
host_source->OverrideContentSecurityPolicy( host_source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ChildSrc, csp); network::mojom::CSPDirectiveName::FrameSrc, csp);
// Register auto-granted permissions. // Register auto-granted permissions.
auto* allowlist = WebUIAllowlist::GetOrCreate(browser_context); auto* allowlist = WebUIAllowlist::GetOrCreate(browser_context);
......
...@@ -56,7 +56,7 @@ SampleSystemWebAppUI::SampleSystemWebAppUI(content::WebUI* web_ui) ...@@ -56,7 +56,7 @@ SampleSystemWebAppUI::SampleSystemWebAppUI(content::WebUI* web_ui)
std::string csp = std::string csp =
std::string("frame-src ") + kChromeUIUntrustedSampleSystemWebAppURL + ";"; std::string("frame-src ") + kChromeUIUntrustedSampleSystemWebAppURL + ";";
trusted_source->OverrideContentSecurityPolicy( trusted_source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ChildSrc, csp); network::mojom::CSPDirectiveName::FrameSrc, csp);
auto* browser_context = web_ui->GetWebContents()->GetBrowserContext(); auto* browser_context = web_ui->GetWebContents()->GetBrowserContext();
content::WebUIDataSource::Add(browser_context, trusted_source.release()); content::WebUIDataSource::Add(browser_context, trusted_source.release());
content::WebUIDataSource::Add(browser_context, content::WebUIDataSource::Add(browser_context,
......
...@@ -71,7 +71,7 @@ TelemetryExtensionUI::TelemetryExtensionUI(content::WebUI* web_ui) ...@@ -71,7 +71,7 @@ TelemetryExtensionUI::TelemetryExtensionUI(content::WebUI* web_ui)
std::string csp = std::string csp =
std::string("frame-src ") + kChromeUIUntrustedTelemetryExtensionURL + ";"; std::string("frame-src ") + kChromeUIUntrustedTelemetryExtensionURL + ";";
trusted_source->OverrideContentSecurityPolicy( trusted_source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ChildSrc, csp); network::mojom::CSPDirectiveName::FrameSrc, csp);
auto* browser_context = web_ui->GetWebContents()->GetBrowserContext(); auto* browser_context = web_ui->GetWebContents()->GetBrowserContext();
content::WebUIDataSource::Add(browser_context, trusted_source.release()); content::WebUIDataSource::Add(browser_context, trusted_source.release());
content::WebUIDataSource::Add(browser_context, content::WebUIDataSource::Add(browser_context,
......
...@@ -62,11 +62,10 @@ content::WebUIDataSource* CreateTrustedSysemAppTestDataSource() { ...@@ -62,11 +62,10 @@ content::WebUIDataSource* CreateTrustedSysemAppTestDataSource() {
auto* trusted_source = content::WebUIDataSource::Create(kSystemAppTestHost); auto* trusted_source = content::WebUIDataSource::Create(kSystemAppTestHost);
// We need a CSP override to be able to embed a chrome-untrusted:// iframe. // We need a CSP override to be able to embed a chrome-untrusted:// iframe.
// TODO(crbug.com/1105408): use FrameSrc instead of ChildSrc.
std::string csp = std::string csp =
std::string("child-src ") + kUntrustedSystemAppTestURL + ";"; std::string("frame-src ") + kUntrustedSystemAppTestURL + ";";
trusted_source->OverrideContentSecurityPolicy( trusted_source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ChildSrc, csp); network::mojom::CSPDirectiveName::FrameSrc, csp);
SetRequestFilterForDataSource(*trusted_source); SetRequestFilterForDataSource(*trusted_source);
return trusted_source; return trusted_source;
......
...@@ -164,6 +164,7 @@ scoped_refptr<net::HttpResponseHeaders> URLDataManagerBackend::GetHeaders( ...@@ -164,6 +164,7 @@ scoped_refptr<net::HttpResponseHeaders> URLDataManagerBackend::GetHeaders(
const network::mojom::CSPDirectiveName kAllDirectives[] = { const network::mojom::CSPDirectiveName kAllDirectives[] = {
network::mojom::CSPDirectiveName::ChildSrc, network::mojom::CSPDirectiveName::ChildSrc,
network::mojom::CSPDirectiveName::DefaultSrc, network::mojom::CSPDirectiveName::DefaultSrc,
network::mojom::CSPDirectiveName::FrameSrc,
network::mojom::CSPDirectiveName::ImgSrc, network::mojom::CSPDirectiveName::ImgSrc,
network::mojom::CSPDirectiveName::MediaSrc, network::mojom::CSPDirectiveName::MediaSrc,
network::mojom::CSPDirectiveName::ObjectSrc, network::mojom::CSPDirectiveName::ObjectSrc,
......
...@@ -279,6 +279,8 @@ TEST_F(WebUIDataSourceTest, SetCspValues) { ...@@ -279,6 +279,8 @@ TEST_F(WebUIDataSourceTest, SetCspValues) {
network::mojom::CSPDirectiveName::ChildSrc)); network::mojom::CSPDirectiveName::ChildSrc));
EXPECT_EQ("", url_data_source->GetContentSecurityPolicy( EXPECT_EQ("", url_data_source->GetContentSecurityPolicy(
network::mojom::CSPDirectiveName::DefaultSrc)); network::mojom::CSPDirectiveName::DefaultSrc));
EXPECT_EQ("", url_data_source->GetContentSecurityPolicy(
network::mojom::CSPDirectiveName::FrameSrc));
EXPECT_EQ("", url_data_source->GetContentSecurityPolicy( EXPECT_EQ("", url_data_source->GetContentSecurityPolicy(
network::mojom::CSPDirectiveName::ImgSrc)); network::mojom::CSPDirectiveName::ImgSrc));
EXPECT_EQ("", url_data_source->GetContentSecurityPolicy( EXPECT_EQ("", url_data_source->GetContentSecurityPolicy(
...@@ -307,6 +309,12 @@ TEST_F(WebUIDataSourceTest, SetCspValues) { ...@@ -307,6 +309,12 @@ TEST_F(WebUIDataSourceTest, SetCspValues) {
url_data_source->GetContentSecurityPolicy( url_data_source->GetContentSecurityPolicy(
network::mojom::CSPDirectiveName::DefaultSrc)); network::mojom::CSPDirectiveName::DefaultSrc));
source()->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::FrameSrc, "frame-src 'self';");
EXPECT_EQ("frame-src 'self';",
url_data_source->GetContentSecurityPolicy(
network::mojom::CSPDirectiveName::FrameSrc));
source()->OverrideContentSecurityPolicy( source()->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ImgSrc, "img-src 'self' blob:;"); network::mojom::CSPDirectiveName::ImgSrc, "img-src 'self' blob:;");
EXPECT_EQ("img-src 'self' blob:;", EXPECT_EQ("img-src 'self' blob:;",
......
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