зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1683593
- Use bracketed IPv6 address to get cookies r=baku
Differential Revision: https://phabricator.services.mozilla.com/D102208
This commit is contained in:
Родитель
49617f2e5c
Коммит
f5724e5421
|
@ -7365,7 +7365,8 @@ uint64_t nsContentUtils::GetInnerWindowID(nsILoadGroup* aLoadGroup) {
|
|||
return inner ? inner->WindowID() : 0;
|
||||
}
|
||||
|
||||
static void MaybeFixIPv6Host(nsACString& aHost) {
|
||||
// static
|
||||
void nsContentUtils::MaybeFixIPv6Host(nsACString& aHost) {
|
||||
if (aHost.FindChar(':') != -1) { // Escape IPv6 address
|
||||
MOZ_ASSERT(!aHost.Length() ||
|
||||
(aHost[0] != '[' && aHost[aHost.Length() - 1] != ']'));
|
||||
|
|
|
@ -2789,6 +2789,11 @@ class nsContentUtils {
|
|||
*/
|
||||
static uint64_t GetInnerWindowID(nsILoadGroup* aLoadGroup);
|
||||
|
||||
/**
|
||||
* Encloses aHost in brackets if it is an IPv6 address.
|
||||
*/
|
||||
static void MaybeFixIPv6Host(nsACString& aHost);
|
||||
|
||||
/**
|
||||
* If the hostname for aURI is an IPv6 it encloses it in brackets,
|
||||
* otherwise it just outputs the hostname in aHost.
|
||||
|
|
|
@ -119,7 +119,13 @@ nsresult CookieCommons::GetBaseDomain(nsIPrincipal* aPrincipal,
|
|||
return nsContentUtils::GetHostOrIPv6WithBrackets(aPrincipal, aBaseDomain);
|
||||
}
|
||||
|
||||
return aPrincipal->GetBaseDomain(aBaseDomain);
|
||||
nsresult rv = aPrincipal->GetBaseDomain(aBaseDomain);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsContentUtils::MaybeFixIPv6Host(aBaseDomain);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Get the base domain for aHost; e.g. for "www.bbc.co.uk", this would be
|
||||
|
|
|
@ -354,7 +354,10 @@ CookieServiceChild::GetCookieStringFromDocument(Document* aDocument,
|
|||
}
|
||||
|
||||
nsAutoCString hostFromURI;
|
||||
principal->GetAsciiHost(hostFromURI);
|
||||
rv = nsContentUtils::GetHostOrIPv6WithBrackets(principal, hostFromURI);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoCString pathFromURI;
|
||||
principal->GetFilePath(pathFromURI);
|
||||
|
|
|
@ -17,3 +17,4 @@ support-files = server.sjs
|
|||
support-files = sameSite.sjs
|
||||
[browser_oversize.js]
|
||||
support-files = oversize.sjs
|
||||
[browser_cookies_ipv6.js]
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
"use strict";
|
||||
|
||||
let { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
|
||||
|
||||
let gHttpServer = null;
|
||||
let ip = "[::1]";
|
||||
|
||||
function contentHandler(metadata, response) {
|
||||
response.setStatusLine(metadata.httpVersion, 200, "Ok");
|
||||
response.setHeader("Content-Type", "text/html", false);
|
||||
let body = `
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<title>Cookie ipv6 Test</title>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>`;
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
}
|
||||
|
||||
add_task(async _ => {
|
||||
if (!gHttpServer) {
|
||||
gHttpServer = new HttpServer();
|
||||
gHttpServer.registerPathHandler("/content", contentHandler);
|
||||
gHttpServer._start(-1, ip);
|
||||
}
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
gHttpServer.stop(() => {
|
||||
gHttpServer = null;
|
||||
});
|
||||
});
|
||||
|
||||
let serverPort = gHttpServer.identity.primaryPort;
|
||||
let testURL = `http://${ip}:${serverPort}/content`;
|
||||
|
||||
// Let's open our tab.
|
||||
const tab = BrowserTestUtils.addTab(gBrowser, testURL);
|
||||
gBrowser.selectedTab = tab;
|
||||
|
||||
const browser = gBrowser.getBrowserForTab(tab);
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
// Test if we can set and get document.cookie successfully.
|
||||
await SpecialPowers.spawn(browser, [], () => {
|
||||
content.document.cookie = "foo=bar";
|
||||
is(content.document.cookie, "foo=bar");
|
||||
});
|
||||
|
||||
// Let's close the tab.
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
Загрузка…
Ссылка в новой задаче