Skip to content

Commit

Permalink
Bug 1802385 - Use NS_GetFinalChannelURI in FetchDriver r=rpl,valentin
Browse files Browse the repository at this point in the history
Depends on D164656

Differential Revision: https://phabricator.services.mozilla.com/D166108
  • Loading branch information
Rob--W committed Jan 16, 2023
1 parent 0c272cf commit df4d1e4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 35 deletions.
10 changes: 1 addition & 9 deletions dom/fetch/FetchDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,14 +1170,6 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest) {

response->InitChannelInfo(channel);

nsCOMPtr<nsIURI> channelURI;
rv = channel->GetURI(getter_AddRefs(channelURI));
if (NS_WARN_IF(NS_FAILED(rv))) {
FailWithNetworkError(rv);
// Cancel request.
return rv;
}

nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
// Propagate any tainting from the channel back to our response here. This
// step is not reflected in the spec because the spec is written such that
Expand Down Expand Up @@ -1494,7 +1486,7 @@ FetchDriver::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
// Response.redirected to true if an internal redirect occurs. These
// should be transparent to script.
nsCOMPtr<nsIURI> uri;
MOZ_ALWAYS_SUCCEEDS(aNewChannel->GetURI(getter_AddRefs(uri)));
MOZ_ALWAYS_SUCCEEDS(NS_GetFinalChannelURI(aNewChannel, getter_AddRefs(uri)));

nsCOMPtr<nsIURI> uriClone;
nsresult rv = NS_GetURIWithoutRef(uri, getter_AddRefs(uriClone));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,16 @@ add_task(async function test_redirect_transform_scheme() {
scheme: "moz-extension",
host: location.hostname,
});
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1745761#c7
// When extensions.webextensions.remote is false (e.g. on Android),
// a redirect to a moz-extension:-URL reveals the underlying jar/file
// URL, instead of the moz-extension:-URL.
// TODO bug 1802385: fix bug and also run the following part on Android.
if (!navigator.userAgent.includes("Android")) {
await testFetch(
"http://from/war.txt",
browser.runtime.getURL("war.txt"),
"Scheme change to moz-extension:-URL"
);
}
await testFetch(
"http://from/war.txt",
browser.runtime.getURL("war.txt"),
"Scheme change to moz-extension:-URL"
);
await testNavigate(
"http://from/war.txt",
browser.runtime.getURL("war.txt"),
"Scheme change to moz-extension:-URL (navigation)"
);
// While the initiator (extension) would be allowed to read the resource
// due to it being same-origin, the pre-redirect URL (http://from) is not
// matching web_accessible_resources[].matches, so the load is rejected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,20 +632,7 @@ add_task(async function redirect_request_with_dnr_to_extensionPath() {
{
let req = await fetch("http://redir/never_reached", { method: "post" });
browser.test.assertEq(200, req.status, "redirected to extensionPath");
if (navigator.userAgent.includes("Android")) {
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1745761#c7
// When extensions.webextensions.remote is false (e.g. on Android),
// a redirect to a moz-extension:-URL reveals the underlying jar/file
// URL, instead of the moz-extension:-URL.
// TODO bug 1802385: fix bug and remove this Android-only check.
browser.test.assertTrue(req.url.endsWith("/war.txt?1"), req.url);
browser.test.assertFalse(
req.url.startsWith(location.origin),
"Work-around for bug 1802385 only needed if URL is not moz-extension:"
);
} else {
browser.test.assertEq(`${location.origin}/war.txt?1`, req.url);
}
browser.test.assertEq(`${location.origin}/war.txt?1`, req.url);
browser.test.assertEq("war_ext_res", await req.text());
}
// Redirects to extensionPath that is not in web_accessible_resources.
Expand Down

0 comments on commit df4d1e4

Please sign in to comment.