Skip to content

Commit d1d729e

Browse files
authored
Fix: hestiacp#3323 Web domain redirect with IDN2 (hestiacp#3325)
* Fix: hestiacp#3323 Web domain redirect with IDN2 Bug was caused by idn2 --quiet $3 that rewrites idn domain to their puny code equivalent version. Causing paths to get rewriten to lowercase. To prevent this issue we split now: $scheme $host and $path and only convert the $host one and keep the reset untouched. * Use "$host" instead
1 parent 889a8cb commit d1d729e

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

bin/v-add-web-domain-redirect

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,22 @@ is_object_unsuspended 'user' 'USER' "$user"
4242
is_object_valid 'web' 'DOMAIN' "$domain"
4343
is_object_unsuspended 'web' 'DOMAIN' "$domain"
4444

45-
idn_redirect=$(idn2 --quiet $3)
46-
if [ $? == 0 ]; then
47-
redirect=$idn_redirect
48-
fi
49-
5045
if [[ "$3" =~ http://|https:// ]]; then
51-
scheme=1
46+
scheme_check=1
47+
scheme=$($HESTIA_PHP -r '$url=parse_url($argv[1]); echo $url["scheme"];' "$redirect")
48+
host=$($HESTIA_PHP -r '$url=parse_url($argv[1]); echo $url["host"];' "$redirect")
49+
path=$($HESTIA_PHP -r '$url=parse_url($argv[1]); if(!empty($url["path"])){echo $url["path"];}' "$redirect")
50+
host=$(idn2 --quiet "$host")
51+
redirect="$scheme://$host$path"
5252
isValidUrl=$(php -r '$url=$argv[1]; $url=filter_var($url,FILTER_VALIDATE_URL); echo $url;' "$redirect")
5353
if [ -z "$isValidUrl" ]; then
5454
check_result $E_INVALID "Invalid redirect"
5555
fi
5656
else
57+
host=$($HESTIA_PHP -r '$url=parse_url($argv[1]); echo $url["host"];' "http://$redirect")
58+
path=$($HESTIA_PHP -r '$url=parse_url($argv[1]); if(!empty($url["path"])){echo $url["path"];}' "http://$redirect")
59+
host=$(idn2 --quiet "$host")
60+
redirect="$host$path"
5761
isValidUrl=$(php -r '$url=$argv[1]; $url=filter_var($url,FILTER_VALIDATE_URL); echo $url;' "http://$redirect")
5862
if [ -z "$isValidUrl" ]; then
5963
check_result $E_INVALID "Invalid redirect"
@@ -72,9 +76,10 @@ if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
7276
conf="$HOMEDIR/$user/conf/web/$domain/nginx.conf_redirect"
7377
sconf="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_redirect"
7478
fi
79+
7580
# Insert redirect commands
7681
if [ -n "$PROXY_SYSTEM" ] || [ "$WEB_SYSTEM" = 'nginx' ]; then
77-
if [ "$scheme" = 1 ]; then
82+
if [ "$scheme_check" = 1 ]; then
7883
echo " return $code $redirect\$request_uri;" > $conf
7984
if [ ! -e "$sconf" ]; then
8085
ln -s "$conf" "$sconf"

func/main.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ BIN=$HESTIA/bin
1717
HESTIA_INSTALL_DIR="$HESTIA/install/deb"
1818
HESTIA_COMMON_DIR="$HESTIA/install/common"
1919
HESTIA_BACKUP="/root/hst_backups/$(date +%d%m%Y%H%M)"
20+
HESTIA_PHP="$HESTIA/php/bin/php"
2021
USER_DATA=$HESTIA/data/users/$user
2122
WEBTPL=$HESTIA/data/templates/web
2223
MAILTPL=$HESTIA/data/templates/mail

0 commit comments

Comments
 (0)