Bug 1635566 - TRR: lowercase cname after reading it from the packet r=necko-reviewers,dragana

Differential Revision: https://phabricator.services.mozilla.com/D75079
This commit is contained in:
Valentin Gosu 2020-05-14 10:52:45 +00:00
Родитель 6ddc89bcb2
Коммит 681c9b474e
3 изменённых файлов: 131 добавлений и 0 удалений

Просмотреть файл

@ -919,6 +919,7 @@ nsresult TRR::DohDecode(nsCString& aHost) {
return rv; return rv;
} }
if (!qname.IsEmpty()) { if (!qname.IsEmpty()) {
ToLowerCase(qname);
mCname = qname; mCname = qname;
LOG(("TRR::DohDecode CNAME host %s => %s\n", host.get(), LOG(("TRR::DohDecode CNAME host %s => %s\n", host.get(),
mCname.get())); mCname.get()));

Просмотреть файл

@ -0,0 +1,129 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const dns = Cc["@mozilla.org/network/dns-service;1"].getService(
Ci.nsIDNSService
);
trr_test_setup();
registerCleanupFunction(async () => {
trr_clear_prefs();
});
function makeChan(url) {
let chan = NetUtil.newChannel({
uri: url,
loadUsingSystemPrincipal: true,
}).QueryInterface(Ci.nsIHttpChannel);
return chan;
}
let processId;
function channelOpenPromise(chan) {
return new Promise(resolve => {
function finish(req, buffer) {
resolve([req, buffer]);
}
chan.asyncOpen(new ChannelListener(finish));
});
}
add_task(async function test_trr_casing() {
let trrServer = new TRRServer();
registerCleanupFunction(async () => trrServer.stop());
await trrServer.start();
dump(`port = ${trrServer.port}\n`);
let chan = makeChan(`https://localhost:${trrServer.port}/test?bla=some`);
let [req, resp] = await channelOpenPromise(chan);
equal(resp, "<h1> 404 Path not found: /test?bla=some</h1>");
dns.clearCache(true);
Services.prefs.setIntPref("network.trr.mode", 3);
Services.prefs.setCharPref(
"network.trr.uri",
`https://foo.example.com:${trrServer.port}/dns-query`
);
// This CNAME response goes to B.example.com (uppercased)
// It should be lowercased by the code
await trrServer.registerDoHAnswers("a.example.com", "A", [
{
name: "a.example.com",
ttl: 55,
type: "CNAME",
flush: false,
data: "B.example.com",
},
]);
// Like in bug 1635566, the response for B.example.com will be lowercased
// by the server too -> b.example.com
// Requesting this resource would case the browser to reject the resource
await trrServer.registerDoHAnswers("B.example.com", "A", [
{
name: "b.example.com",
ttl: 55,
type: "CNAME",
flush: false,
data: "c.example.com",
},
]);
// The browser should request this one
await trrServer.registerDoHAnswers("b.example.com", "A", [
{
name: "b.example.com",
ttl: 55,
type: "CNAME",
flush: false,
data: "c.example.com",
},
]);
// Finally, it gets an IP
await trrServer.registerDoHAnswers("c.example.com", "A", [
{
name: "c.example.com",
ttl: 55,
type: "A",
flush: false,
data: "1.2.3.4",
},
]);
await new TRRDNSListener("a.example.com", "1.2.3.4");
await trrServer.registerDoHAnswers("a.test.com", "A", [
{
name: "a.test.com",
ttl: 55,
type: "CNAME",
flush: false,
data: "B.test.com",
},
]);
// We try this again, this time we explicitly make sure this resource
// is never used
await trrServer.registerDoHAnswers("B.test.com", "A", [
{
name: "B.test.com",
ttl: 55,
type: "A",
flush: false,
data: "9.9.9.9",
},
]);
await trrServer.registerDoHAnswers("b.test.com", "A", [
{
name: "b.test.com",
ttl: 55,
type: "A",
flush: false,
data: "8.8.8.8",
},
]);
await new TRRDNSListener("a.test.com", "8.8.8.8");
await trrServer.stop();
});

Просмотреть файл

@ -426,3 +426,4 @@ skip-if = true || asan || tsan || os == 'win' || os =='android'
[test_dns_override.js] [test_dns_override.js]
[test_no_cookies_after_last_pb_exit.js] [test_no_cookies_after_last_pb_exit.js]
[test_trr_httpssvc.js] [test_trr_httpssvc.js]
[test_trr_case_sensitivity.js]