Commit 68badfdb authored by Fabrice de Gans-Riberi's avatar Fabrice de Gans-Riberi Committed by Commit Bot

[fuchsia] Do not treat URL request rewrites to data URLs as cross-scheme redirects.

* Skip the scheme redirect check for rewritten data URLs.
* Do not append query and ref to rewritten data URLs.

Bug: 1014237

Change-Id: Ied4b9495031c2f86c196b036aeeb6d599cd98560
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1846811Reviewed-by: default avatarWez <wez@chromium.org>
Commit-Queue: Fabrice de Gans-Riberi <fdegans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707427}
parent fac39a19
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "fuchsia/engine/common/web_engine_url_loader_throttle.h" #include "fuchsia/engine/common/web_engine_url_loader_throttle.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "url/url_constants.h"
namespace { namespace {
...@@ -55,6 +56,11 @@ void ApplyReplaceUrl(network::ResourceRequest* request, ...@@ -55,6 +56,11 @@ void ApplyReplaceUrl(network::ResourceRequest* request,
return; return;
GURL new_url = replace_url->new_url; GURL new_url = replace_url->new_url;
if (new_url.SchemeIs(url::kDataScheme)) {
request->url = new_url;
return;
}
if (new_url.has_scheme() && if (new_url.has_scheme() &&
new_url.scheme().compare(request->url.scheme()) != 0) { new_url.scheme().compare(request->url.scheme()) != 0) {
// No cross-scheme redirect allowed. // No cross-scheme redirect allowed.
......
...@@ -90,3 +90,37 @@ TEST_F(WebEngineURLLoaderThrottleTest, WildcardHosts) { ...@@ -90,3 +90,37 @@ TEST_F(WebEngineURLLoaderThrottleTest, WildcardHosts) {
throttle.WillStartRequest(&request4, &defer); throttle.WillStartRequest(&request4, &defer);
EXPECT_FALSE(request4.headers.HasHeader("Header")); EXPECT_FALSE(request4.headers.HasHeader("Header"));
} }
// Tests URL replacement rules that replace to a data URL do not append query or
// ref from the original URL.
TEST_F(WebEngineURLLoaderThrottleTest, DataReplacementUrl) {
const char kCssDataURI[] = "data:text/css,";
mojom::UrlRequestRewriteReplaceUrlPtr replace_url =
mojom::UrlRequestRewriteReplaceUrl::New();
replace_url->url_ends_with = ".css";
replace_url->new_url = GURL(kCssDataURI);
mojom::UrlRequestRewritePtr rewrite =
mojom::UrlRequestRewrite::NewReplaceUrl(std::move(replace_url));
std::vector<mojom::UrlRequestRewritePtr> rewrites;
rewrites.push_back(std::move(rewrite));
mojom::UrlRequestRewriteRulePtr rule = mojom::UrlRequestRewriteRule::New();
rule->hosts_filter = base::Optional<std::vector<std::string>>({"*.test.net"});
rule->rewrites = std::move(rewrites);
std::vector<mojom::UrlRequestRewriteRulePtr> rules;
rules.push_back(std::move(rule));
TestCachedRulesProvider provider;
provider.SetCachedRules(
base::MakeRefCounted<WebEngineURLLoaderThrottle::UrlRequestRewriteRules>(
std::move(rules)));
WebEngineURLLoaderThrottle throttle(&provider);
bool defer = false;
network::ResourceRequest request;
request.url = GURL("http://test.net/style.css?query#ref");
throttle.WillStartRequest(&request, &defer);
EXPECT_EQ(request.url, base::StringPiece(kCssDataURI));
}
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