Security hardening: enforce secure URLs and transport safeguards

This commit is contained in:
Andy Dixon
2026-02-26 09:10:09 +00:00
parent 94c85fc8d5
commit 3ff5b7aa26
6 changed files with 185 additions and 11 deletions
+39
View File
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace BlackWall\Auth\Tests;
use BlackWall\Auth\Config;
use PHPUnit\Framework\TestCase;
final class ConfigSecurityTest extends TestCase
{
public function testRejectsInsecureHttpForNonLocalhostByDefault(): void
{
$this->expectException(\InvalidArgumentException::class);
Config::fromArray([
'clientId' => 'client-123',
'authorizeUrl' => 'http://provider.example/oauth/authorize',
'tokenUrl' => 'https://provider.example/oauth/token',
'userInfoUrl' => 'https://provider.example/oauth/userinfo',
'redirectUri' => 'https://app.example/callback.php',
]);
}
public function testAllowsInsecureHttpForLocalhostWhenExplicitlyEnabled(): void
{
$config = Config::fromArray([
'clientId' => 'client-123',
'authorizeUrl' => 'http://localhost/oauth/authorize',
'tokenUrl' => 'http://127.0.0.1/oauth/token',
'userInfoUrl' => 'http://localhost/oauth/userinfo',
'redirectUri' => 'http://localhost/callback.php',
'allowInsecureHttp' => true,
]);
self::assertTrue($config->allowInsecureHttp);
self::assertSame('http://localhost/oauth/authorize', $config->authorizeUrl);
}
}