45 lines
2 KiB
PHP
45 lines
2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Steuerkram\Services\SsrfGuard;
|
|
|
|
class SsrfGuardTest extends TestCase
|
|
{
|
|
protected string $testName = 'Test 51: SSRF-Schutz für fints_url (Positivliste https + öffentliche Hosts)';
|
|
|
|
public function run(): void
|
|
{
|
|
// Nicht-https-Schema wird abgelehnt
|
|
$this->assertRejected('http://banking.example.com/fints', 'http:// wird abgelehnt');
|
|
|
|
// IP-Literale in privaten/reservierten Bereichen werden abgelehnt
|
|
$this->assertRejected('https://127.0.0.1/fints', 'Loopback-IP (127.0.0.1) wird abgelehnt');
|
|
$this->assertRejected('https://localhost/fints', 'localhost wird abgelehnt');
|
|
$this->assertRejected('https://10.0.0.5/fints', 'RFC1918-IP (10.0.0.5) wird abgelehnt');
|
|
$this->assertRejected('https://192.168.1.1/fints', 'RFC1918-IP (192.168.1.1) wird abgelehnt');
|
|
$this->assertRejected('https://169.254.169.254/fints', 'Link-Local/Metadata-IP (169.254.169.254) wird abgelehnt');
|
|
$this->assertRejected('https://[::1]/fints', 'IPv6-Loopback wird abgelehnt');
|
|
|
|
// Credentials in der URL sind nicht erlaubt (potenzielles Injection-/Redirect-Ziel)
|
|
$this->assertRejected('https://user:pass@banking.example.com/fints', 'Userinfo in der URL wird abgelehnt');
|
|
|
|
// Öffentliche IP-Literale und Hostnamen mit https werden akzeptiert
|
|
try {
|
|
SsrfGuard::assertPublicHttpsUrl('https://8.8.8.8/fints');
|
|
$this->assert(true, 'Öffentliche IP-Literal (8.8.8.8) wird akzeptiert');
|
|
} catch (\RuntimeException $e) {
|
|
$this->assert(false, 'Öffentliche IP-Literal (8.8.8.8) wird akzeptiert (Fehler: ' . $e->getMessage() . ')');
|
|
}
|
|
}
|
|
|
|
private function assertRejected(string $url, string $message): void
|
|
{
|
|
try {
|
|
SsrfGuard::assertPublicHttpsUrl($url);
|
|
$this->assert(false, $message);
|
|
} catch (\RuntimeException $e) {
|
|
$this->assert(true, $message);
|
|
}
|
|
}
|
|
}
|