| Server IP : 202.61.199.114 / Your IP : 216.73.217.139 Web Server : nginx/1.22.1 System : Linux de.arni-solutions.de 6.1.0-49-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.174-1 (2026-05-26) x86_64 User : web20 ( 1018) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/clients/client2/web21/web/api/lib/ |
Upload File : |
<?php
/**
* Eingabe-Validierung + SSRF-/Missbrauchsschutz.
*
* @package SafeMyIdent\Api
*/
declare(strict_types=1);
/**
* Validiert und normalisiert einen Domainnamen.
*
* @param string $domain Roh-Eingabe.
* @return string|null Normalisierte Domain oder null bei Ungültigkeit.
*/
function smi_valid_domain(string $domain): ?string
{
$domain = strtolower(trim($domain));
// Evtl. Schema/Pfad entfernen.
if (str_contains($domain, '://')) {
$domain = (string) parse_url($domain, PHP_URL_HOST);
}
$domain = trim($domain, '.');
if ($domain === '' || strlen($domain) > 253) {
return null;
}
// Interne/lokale Ziele ausschließen (SSRF-Schutz).
$blocked = ['localhost', 'localhost.localdomain'];
if (in_array($domain, $blocked, true)) {
return null;
}
if (filter_var($domain, FILTER_VALIDATE_IP)) {
return null; // Nur Domains, keine IPs.
}
// Gültiges Domain-Muster (Labels, TLD ≥ 2).
if (!preg_match('/^(?=.{1,253}$)([a-z0-9](-?[a-z0-9])*)(\.[a-z0-9](-?[a-z0-9])*)*\.[a-z]{2,}$/', $domain)) {
return null;
}
// IDN → Punycode, falls verfügbar.
if (function_exists('idn_to_ascii')) {
$ascii = idn_to_ascii($domain, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46);
if (is_string($ascii) && $ascii !== '') {
$domain = $ascii;
}
}
return $domain;
}