addHttpSchemeAsFallback($parameters['url']); } /** * Returns the URL as is * * @param array $data (needs 'url') inside */ public function resolveHandlerData(array $data): array { return ['url' => $this->addHttpSchemeAsFallback($data['url'])]; } /** * Ensures that a scheme is always added, if www.typo3.org was added previously. * * @param string $url the URL */ protected function addHttpSchemeAsFallback(string $url): string { if (!empty($url)) { // We expect this an absolute path, and leave as is. We also leave double slashes ('//') as is. if (str_starts_with($url, '/')) { return $url; } $scheme = parse_url($url, PHP_URL_SCHEME); if (empty($scheme)) { $url = self::getDefaultScheme() . '://' . $url; } elseif (in_array(strtolower($scheme), ['javascript', 'data'], true)) { // deny using insecure scheme's like `javascript:` or `data:` as URL scheme $url = ''; } } return $url; } /** * Returns the scheme (e.g. `http`) to be used for links with URLs without a scheme, e.g., for `www.example.com`. * * @return non-empty-string */ public static function getDefaultScheme(): string { return ($GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultScheme'] ?? '') ?: LinkHandlingInterface::DEFAULT_SCHEME; } }