[BUGFIX] Catch error in GeneralUtility::validEmail and GeneralUtility:isValidUrl 21/53121/6
authorNicole Cordes <typo3@cordes.co>
Mon, 5 Jun 2017 12:32:31 +0000 (14:32 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Sun, 30 Jul 2017 17:32:34 +0000 (19:32 +0200)
If a wrong email address or URL is parsed and the domain cannot be converted,
an exception is thrown by \Mso\IdnaConvert\IdnaConvert::encode(). This
exception needs to be caught.

Resolves: #81471
Releases: master, 8.7, 7.6
Change-Id: I76f9b8898655d9220e5176a60f388067a6c493b3
Reviewed-on: https://review.typo3.org/53121
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php

index ef62095..8e48257 100644 (file)
@@ -914,7 +914,11 @@ class GeneralUtility
         $domain = substr($email, $atPosition + 1);
         $user = substr($email, 0, $atPosition);
         if (!preg_match('/^[a-z0-9.\\-]*$/i', $domain)) {
-            $domain = self::idnaEncode($domain);
+            try {
+                $domain = self::idnaEncode($domain);
+            } catch (\InvalidArgumentException $exception) {
+                return false;
+            }
         }
         return filter_var($user . '@' . $domain, FILTER_VALIDATE_EMAIL) !== false;
     }
@@ -1018,7 +1022,11 @@ class GeneralUtility
             return false;
         }
         if (isset($parsedUrl['host']) && !preg_match('/^[a-z0-9.\\-]*$/i', $parsedUrl['host'])) {
-            $parsedUrl['host'] = self::idnaEncode($parsedUrl['host']);
+            try {
+                $parsedUrl['host'] = self::idnaEncode($parsedUrl['host']);
+            } catch (\InvalidArgumentException $exception) {
+                return false;
+            }
         }
         return filter_var(HttpUtility::buildUrl($parsedUrl), FILTER_VALIDATE_URL) !== false;
     }
index 7534fa7..9b35773 100644 (file)
@@ -981,7 +981,8 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
             'trailing carriage return' => ['test@example.com' . CR],
             'trailing linefeed' => ['test@example.com' . LF],
             'trailing carriage return linefeed' => ['test@example.com' . CRLF],
-            'trailing tab' => ['test@example.com' . TAB]
+            'trailing tab' => ['test@example.com' . TAB],
+            'prohibited input characters' => ['“mailto:test@example.com”'],
         ];
     }
 
@@ -1902,6 +1903,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
             'string array()' => ['array()'],
             'random string' => ['qwe'],
             'http directory umlauts' => ['http://www.oebb.at/äöü/'],
+            'prohibited input characters' => ['https://{$unresolved_constant}'],
         ];
     }