‪TYPO3CMS  11.5
UrlLinkHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 {
29  public function ‪asString(array $parameters): string
30  {
31  return $this->‪addHttpSchemeAsFallback($parameters['url']);
32  }
33 
40  public function ‪resolveHandlerData(array $data): array
41  {
42  return ['url' => $this->‪addHttpSchemeAsFallback($data['url'])];
43  }
44 
51  protected function ‪addHttpSchemeAsFallback(string $url): string
52  {
53  if (!empty($url)) {
54  if (str_starts_with($url, '//')) {
55  return $url;
56  }
57  $scheme = parse_url($url, PHP_URL_SCHEME);
58  if (empty($scheme)) {
59  $url = ‪self::getDefaultScheme() . '://' . $url;
60  } elseif (in_array(strtolower($scheme), ['javascript', 'data'], true)) {
61  // deny using insecure scheme's like `javascript:` or `data:` as URL scheme
62  $url = '';
63  }
64  }
65  return $url;
66  }
67 
73  public static function ‪getDefaultScheme(): string
74  {
75  return (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultScheme'] ?? '')
77  }
78 }
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25