mirror of
https://github.com/pi-hole/web.git
synced 2026-04-27 12:15:00 +01:00
Do not fail if IDNA<->UNICODE conversion fails
Signed-off-by: Christian König <ckoenig@posteo.de>
This commit is contained in:
committed by
yubiuser
parent
92a5154c79
commit
68ac05fb7e
@@ -640,7 +640,7 @@ function getGateway()
|
||||
}
|
||||
|
||||
// Try to convert possible IDNA domain to Unicode
|
||||
function convertIDNAToUnicode($unicode)
|
||||
function convertIDNAToUnicode($IDNA)
|
||||
{
|
||||
if (extension_loaded('intl')) {
|
||||
// we try the UTS #46 standard first
|
||||
@@ -652,32 +652,42 @@ function convertIDNAToUnicode($unicode)
|
||||
// to ensure sparkasse-gießen.de is not converted into
|
||||
// sparkass-giessen.de but into xn--sparkasse-gieen-2ib.de
|
||||
// as mandated by the UTS #46 standard
|
||||
$unicode = idn_to_utf8($unicode, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
|
||||
$unicode = idn_to_utf8($IDNA, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
|
||||
} elseif (defined('INTL_IDNA_VARIANT_2003')) {
|
||||
// If conversion failed, try with the (deprecated!) IDNA 2003 variant
|
||||
// We have to check for its existence as support of this variant is
|
||||
// scheduled for removal with PHP 8.0
|
||||
// see https://wiki.php.net/rfc/deprecate-and-remove-intl_idna_variant_2003
|
||||
$unicode = idn_to_utf8($unicode, IDNA_DEFAULT, INTL_IDNA_VARIANT_2003);
|
||||
$unicode = idn_to_utf8($IDNA, IDNA_DEFAULT, INTL_IDNA_VARIANT_2003);
|
||||
}
|
||||
}
|
||||
|
||||
return $unicode;
|
||||
// if the conversion failed (e.g. domain to long) return the original domain
|
||||
if ($unicode == false) {
|
||||
return $IDNA;
|
||||
} else {
|
||||
return $unicode;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert a given (unicode) domain to IDNA ASCII
|
||||
function convertUnicodeToIDNA($IDNA)
|
||||
function convertUnicodeToIDNA($unicode)
|
||||
{
|
||||
if (extension_loaded('intl')) {
|
||||
// Be prepared that this may fail and see our comments about convertIDNAToUnicode()
|
||||
if (defined('INTL_IDNA_VARIANT_UTS46')) {
|
||||
$IDNA = idn_to_ascii($IDNA, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
|
||||
$IDNA = idn_to_ascii($unicode, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
|
||||
} elseif (defined('INTL_IDNA_VARIANT_2003')) {
|
||||
$IDNA = idn_to_ascii($IDNA, IDNA_DEFAULT, INTL_IDNA_VARIANT_2003);
|
||||
$IDNA = idn_to_ascii($unicode, IDNA_DEFAULT, INTL_IDNA_VARIANT_2003);
|
||||
}
|
||||
}
|
||||
|
||||
return $IDNA;
|
||||
// if the conversion failed (e.g. domain to long) return the original domain
|
||||
if ($IDNA == false) {
|
||||
return $unicode;
|
||||
} else {
|
||||
return $IDNA;
|
||||
}
|
||||
}
|
||||
|
||||
// Return PID of FTL (used in settings.php)
|
||||
|
||||
@@ -510,14 +510,11 @@ if ($_POST['action'] == 'get_groups') {
|
||||
$res['groups'] = $groups;
|
||||
if ($res['type'] === LISTTYPE_WHITELIST || $res['type'] === LISTTYPE_BLACKLIST) {
|
||||
// Convert domain name to international form
|
||||
// Skip this for the root zone `.`
|
||||
if ($res['domain'] != '.') {
|
||||
$utf8_domain = convertIDNAToUnicode($res['domain']);
|
||||
$utf8_domain = convertIDNAToUnicode($res['domain']);
|
||||
|
||||
// if domain and international form are different, show both
|
||||
if ($res['domain'] !== $utf8_domain) {
|
||||
$res['domain'] = $utf8_domain.' ('.$res['domain'].')';
|
||||
}
|
||||
// if domain and international form are different, show both
|
||||
if ($res['domain'] !== $utf8_domain) {
|
||||
$res['domain'] = $utf8_domain.' ('.$res['domain'].')';
|
||||
}
|
||||
}
|
||||
// Prevent domain and comment fields from returning any arbitrary javascript code which could be executed on the browser.
|
||||
@@ -600,10 +597,7 @@ if ($_POST['action'] == 'get_groups') {
|
||||
// If not adding a RegEx....
|
||||
$input = $domain;
|
||||
// Convert domain name to IDNA ASCII form for international domains
|
||||
// Skip this for the root zone `.`
|
||||
if ($domain != '.') {
|
||||
$domain = convertUnicodeToIDNA($domain);
|
||||
}
|
||||
$domain = convertUnicodeToIDNA($domain);
|
||||
// convert the domain lower case and check whether it is valid
|
||||
$domain = strtolower($domain);
|
||||
$msg = '';
|
||||
|
||||
Reference in New Issue
Block a user