toLowerCase domains on punycode convert (uppercase "not a legal IDNA2008 name")

parent 379cce79
......@@ -13,6 +13,10 @@ function catcher(x) {
return;
}
function punyCodeLower(input: string): string {
return punycode.toASCII(punycode.toUnicode(input).toLowerCase());
}
/**
* Index
*/
......@@ -22,36 +26,49 @@ router.get("/:domain", (req: Request, res: Response, next: NextFunction) => {
if(isIp(asciiDomain)) {
res.redirect(301, `/ip/${asciiDomain}`);
} else if(domainNameRegex.test(asciiDomain) || isDomainName(asciiDomain)) {
axios.get(`https://api.telcodb.net/v1/resolve?format=json&q=${asciiDomain}`)
.then((response) => {
Promise.all([
getIpInfo(response.data).catch(catcher)
])
.then(x => x[0])
.then(ipInfo => {
// Nullify IP info if undefined
if(ipInfo[0] == undefined) {
ipInfo = null;
}
const unicodeDomain = punycode.toUnicode(asciiDomain);
res.render("dns/show.twig", {
"title": `${unicodeDomain} - DNS data`,
"disable_title_prefix": true,
"canonical_url": `/dns/${asciiDomain}`,
"asciiDomain": asciiDomain,
"unicodeDomain": unicodeDomain,
"data": response.data,
"ipInfo": ipInfo,
if(asciiDomain.toLowerCase() != asciiDomain) {
res.redirect(`/dns/${asciiDomain.toLowerCase()}`);
} else if(punyCodeLower(asciiDomain) !== asciiDomain) {
/**
* Example: https://telcodb.net/dns/xn--ggle-lmaa.com ("gÖÖgle.com")
*
* dig: 'xn--ggle-lmaa.com' is not a legal IDNA2008 name (domain label has character forbidden in non-transitional mode (TR46)), use +noidnin
*
* "dig gÖÖgle.com" returns results for xn--ggle-5qaa.com
*/
res.redirect(301, `/dns/${punyCodeLower(asciiDomain)}`);
} else {
axios.get(`https://api.telcodb.net/v1/resolve?format=json&q=${asciiDomain}`)
.then((response) => {
Promise.all([
getIpInfo(response.data).catch(catcher)
])
.then(x => x[0])
.then(ipInfo => {
// Nullify IP info if undefined
if(ipInfo[0] == undefined) {
ipInfo = null;
}
const unicodeDomain = punycode.toUnicode(asciiDomain);
res.render("dns/show.twig", {
"title": `${unicodeDomain} - DNS data`,
"disable_title_prefix": true,
"canonical_url": `/dns/${asciiDomain}`,
"asciiDomain": asciiDomain,
"unicodeDomain": unicodeDomain,
"data": response.data,
"ipInfo": ipInfo,
});
});
});
})
.catch(next);
})
.catch(next);
}
} else if(isIdn(asciiDomain)) {
res.redirect(`/dns/${punycode.toASCII(asciiDomain)}`)
} else {
......
......@@ -38,7 +38,7 @@ router.get("/", (req: Request, res: Response, next: NextFunction) => {
} else if(isCidr(query)) {
res.redirect(`/net/${query}`);
} else if(domainNameRegex.test(punycode.toASCII(query))) {
res.redirect(`/dns/${punycode.toASCII(query)}`);
res.redirect(`/dns/${punycode.toASCII(query.toLowerCase())}`);
} else {
let skip_tld_check: boolean = false;
......
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