Sicherheitsupdate nach Audit (0.29.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m50s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m34s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m45s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m30s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m7s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m9s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m8s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m5s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 48s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m5s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 11:34:54 +00:00
parent a37895a16a
commit f1202bea08
226 changed files with 1952 additions and 450 deletions

View file

@ -32,12 +32,15 @@ class MailSettingsTest extends TestCase
$this->assertSame('geheim123', config('mail.mailers.smtp.password'));
$this->assertSame('intranet@firma.de', config('mail.from.address'));
// Leeres Passwort behält das gespeicherte.
Livewire::test(MailSettingsPage::class)->assertFormSet(['password' => null])->fillForm(['host' => 'mail.firma.de'])->call('save');
// Leeres Passwort behält das gespeicherte – solange der Server gleich bleibt.
Livewire::test(MailSettingsPage::class)->assertFormSet(['password' => null])->fillForm(['from_name' => 'Portal'])->call('save')->assertHasNoFormErrors();
config(['mail.mailers.smtp.password' => null]);
app(MailSettings::class)->apply();
$this->assertSame('geheim123', config('mail.mailers.smtp.password'));
$this->assertSame('mail.firma.de', config('mail.mailers.smtp.host'));
// Anderer Server: Passwort muss neu eingegeben werden (sonst ginge es an den neuen Server)
Livewire::test(MailSettingsPage::class)->fillForm(['host' => 'mail.angreifer.example'])->call('save')->assertHasFormErrors(['password']);
$this->assertSame('smtp.office365.com', app(Settings::class)->get('mail.host'));
}
public function test_only_permitted_people_open_the_page(): void

View file

@ -0,0 +1,77 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\IdentityProvider;
use App\Models\User;
use App\Models\UserIdentity;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
class AccountSecurityTest extends TestCase
{
use RefreshDatabase;
public function test_deactivated_people_are_logged_out_and_lose_all_access(): void
{
$user = User::factory()->create();
$token = $user->createToken('Handy')->plainTextToken;
$rememberBefore = $user->fresh()->remember_token;
$this->actingAs($user)->get('/')->assertOk();
$user->update(['is_active' => false]);
$this->get('/neuigkeiten')->assertRedirect('/login');
$this->assertGuest();
$this->assertSame(0, $user->tokens()->count());
$this->assertNotSame($rememberBefore, $user->fresh()->remember_token);
$this->app['auth']->forgetGuards();
$this->withToken($token)->getJson('/api/v1/me')->assertUnauthorized();
}
public function test_password_reset_is_neutral_and_not_for_sso_only_accounts(): void
{
Notification::fake();
$local = User::factory()->create(['email' => 'lokal@example.org']);
$sso = User::factory()->create(['email' => 'sso@example.org', 'password' => null]);
$provider = IdentityProvider::query()->create(['type' => 'entra', 'name' => 'Entra', 'slug' => 'entra', 'enabled' => true, 'config' => []]);
UserIdentity::query()->create(['user_id' => $sso->id, 'identity_provider_id' => $provider->id, 'subject' => 'abc']);
$unknown = $this->post('/forgot-password', ['email' => 'gibtsnicht@example.org'])->assertSessionHasNoErrors()->assertSessionHas('status')->baseResponse->getSession()->get('status');
$this->post('/forgot-password', ['email' => 'lokal@example.org'])->assertSessionHasNoErrors()->assertSessionHas('status', $unknown);
$this->post('/forgot-password', ['email' => 'sso@example.org'])->assertSessionHasNoErrors()->assertSessionHas('status', $unknown);
Notification::assertSentTo($local, ResetPassword::class);
Notification::assertNotSentTo($sso, ResetPassword::class);
}
public function test_password_change_revokes_other_sessions_and_tokens(): void
{
$user = User::factory()->create(['password' => 'alt-Passwort-123']);
$user->createToken('Handy');
DB::table('sessions')->insert(['id' => 'fremdes-geraet', 'user_id' => $user->id, 'payload' => '', 'last_activity' => time()]);
$this->actingAs($user)->put('/user/password', [
'current_password' => 'alt-Passwort-123', 'password' => 'Neues-Passwort-456!', 'password_confirmation' => 'Neues-Passwort-456!',
])->assertSessionHasNoErrors();
$this->assertSame(0, $user->tokens()->count());
$this->assertFalse(DB::table('sessions')->where('id', 'fremdes-geraet')->exists());
}
public function test_api_token_login_is_limited_per_address(): void
{
User::factory()->create(['email' => 'ada@example.org', 'password' => 'geheim-123']);
foreach (range(1, 5) as $i) {
$this->postJson('/api/v1/token', ['email' => 'ada@example.org', 'password' => 'falsch', 'device_name' => 'x'], ['REMOTE_ADDR' => "10.0.0.{$i}"])->assertUnprocessable();
}
$this->postJson('/api/v1/token', ['email' => 'ada@example.org', 'password' => 'geheim-123', 'device_name' => 'x'], ['REMOTE_ADDR' => '10.0.0.9'])
->assertUnprocessable()->assertJsonPath('errors.email.0', 'Zu viele Versuche. Bitte in einigen Minuten erneut versuchen.');
}
}

View file

@ -15,6 +15,7 @@ use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Storage;
use Inertia\Testing\AssertableInertia as Assert;
use Inhaus\Plugins\Forms\Filament\Resources\Forms\Pages\CreateForm;
use Inhaus\Plugins\Forms\Filament\Resources\Forms\Pages\EditForm;
use Inhaus\Plugins\Forms\Filament\Resources\Forms\Pages\FormResults;
use Inhaus\Plugins\Forms\Filament\Resources\Forms\Pages\ListForms;
use Inhaus\Plugins\Forms\Mail\FormSubmitted;
@ -388,4 +389,23 @@ class FormsTest extends TestCase
$this->assertArrayNotHasKey('locked', $saved[1]['data']);
$this->assertArrayNotHasKey('locked', $saved[2]['data']);
}
public function test_form_editors_without_result_access_cannot_redirect_submissions(): void
{
$form = $this->trainingForm(['notify_emails' => ['personal@firma.de'], 'anonymous' => true]);
$role = Role::query()->create(['name' => 'Formular-Redaktion']);
$role->grants()->create(['ability' => 'forms.edit', 'resource_type' => 'form', 'resource_id' => $form->id]);
$role->grants()->create(['ability' => 'news.manage']); // Zugang zum Backend
$editor = User::factory()->withRoles([$role])->create();
$this->actingAs($editor);
Livewire::test(EditForm::class, ['record' => $form->getRouteKey()])
->set('data.settings.notify_emails', ['angreifer@example.org'])
->set('data.settings.anonymous', false)
->call('save');
$settings = $form->fresh()->settings;
$this->assertSame(['personal@firma.de'], $settings['notify_emails']);
$this->assertTrue($settings['anonymous']);
}
}

View file

@ -0,0 +1,43 @@
<?php
namespace Tests\Feature\Identity;
use App\Identity\IdentityException;
use App\Identity\IdentitySync;
use App\Models\IdentityProvider;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class EmailLinkingTest extends TestCase
{
use RefreshDatabase;
private function provider(string $type, array $config = []): IdentityProvider
{
return IdentityProvider::query()->create(['type' => $type, 'name' => ucfirst($type), 'slug' => $type, 'enabled' => true, 'config' => ['link_by_email' => true, ...$config]]);
}
public function test_privileged_accounts_are_not_linked_by_an_unverified_address(): void
{
$admin = User::factory()->admin()->create(['email' => 'chef@firma.de']);
$this->expectException(IdentityException::class);
app(IdentitySync::class)->resolveUser($this->provider('ldap'), 'uid=eve', ['email' => 'chef@firma.de'], true);
}
public function test_accounts_without_password_and_rights_still_link(): void
{
$user = User::factory()->create(['email' => 'anna@firma.de', 'password' => null]);
$this->assertTrue(app(IdentitySync::class)->resolveUser($this->provider('saml'), 'anna', ['email' => 'anna@firma.de'], true)->is($user));
}
public function test_verified_or_trusted_addresses_link_privileged_accounts(): void
{
$admin = User::factory()->admin()->create(['email' => 'chef@firma.de']);
$this->assertTrue(app(IdentitySync::class)->resolveUser($this->provider('oidc'), 'sub-1', ['email' => 'chef@firma.de', 'email_verified' => true], true)->is($admin));
$this->assertTrue(app(IdentitySync::class)->resolveUser($this->provider('ldap', ['trust_email' => true]), 'uid=chef', ['email' => 'chef@firma.de'], true)->is($admin));
}
}

View file

@ -260,13 +260,22 @@ class ItServiceTest extends TestCase
{
Livewire::actingAs(User::factory()->admin()->create())
->test(ItServiceSettings::class)
->set('data.url', 'https://it.example.org/api/ex')
->set('data.url', self::BASE)
->set('data.token', '')
->set('data.secret', 'neu-geheim')
->set('data.auto_reserve', 'no')
->call('save')
->assertHasNoErrors();
// Neue Adresse ohne neue Zugangsdaten: abgelehnt (sonst ginge das gespeicherte Token dorthin)
Livewire::actingAs(User::factory()->admin()->create())
->test(ItServiceSettings::class)
->set('data.url', 'https://angreifer.example/api/ex')
->set('data.token', '')
->set('data.secret', '')
->call('save')
->assertHasErrors(['data.token']);
$settings = app(Settings::class);
$this->assertSame('tok-123', $settings->token(), 'leer gelassen = unverändert');
$this->assertSame('neu-geheim', $settings->secret());

View file

@ -53,11 +53,11 @@ class WebPushTest extends TestCase
[$uaPrivate, $uaPublic, $auth] = $this->browserKeys();
$user = User::factory()->create();
$subscription = PushSubscription::query()->create([
'user_id' => $user->id, 'endpoint' => 'https://push.example.org/send/abc', 'endpoint_hash' => hash('sha256', 'x'),
'user_id' => $user->id, 'endpoint' => 'https://fcm.googleapis.com/fcm/send/abc', 'endpoint_hash' => hash('sha256', 'x'),
'public_key' => $uaPublic, 'auth_token' => $auth,
]);
Http::fake(['push.example.org/*' => Http::response('', 201)]);
Http::fake(['fcm.googleapis.com/*' => Http::response('', 201)]);
$push = app(WebPush::class);
$this->assertTrue($push->send($subscription, ['title' => 'Freigabe', 'body' => 'Ümläute & mehr']));
@ -70,7 +70,7 @@ class WebPushTest extends TestCase
preg_match('/^vapid t=([^,]+), k=(.+)$/', $request->header('Authorization')[0], $m);
$this->assertSame($push->publicKey(), $m[2]);
[$header, $claims, $signature] = explode('.', $m[1]);
$this->assertSame('https://push.example.org', json_decode(WebPush::base64UrlDecode($claims), true)['aud']);
$this->assertSame('https://fcm.googleapis.com', json_decode(WebPush::base64UrlDecode($claims), true)['aud']);
$raw = WebPush::base64UrlDecode($signature);
$int = fn (string $v) => "\x02".chr(strlen($v = ltrim($v, "\0")) + (ord($v[0]) > 0x7F ? 1 : 0)).(ord($v[0]) > 0x7F ? "\0" : '').$v;
$der = $int(substr($raw, 0, 32)).$int(substr($raw, 32));
@ -89,13 +89,17 @@ class WebPushTest extends TestCase
$this->actingAs($user)->get('/')->assertInertia(fn ($page) => $page->where('push.key', app(WebPush::class)->publicKey()));
$this->postJson('/push/abo', ['endpoint' => 'http://unsicher.example.org/x', 'keys' => ['p256dh' => $uaPublic, 'auth' => $auth]])->assertUnprocessable();
$this->postJson('/push/abo', ['endpoint' => 'https://push.example.org/send/1', 'keys' => ['p256dh' => $uaPublic, 'auth' => $auth]])->assertOk();
// Nur bekannte Push-Dienste – keine internen Adressen (SSRF)
foreach (['https://10.0.0.5:8443/admin', 'https://127.0.0.1/x', 'https://fcm.googleapis.com.evil.test/x', 'https://evil.test/fcm.googleapis.com'] as $endpoint) {
$this->postJson('/push/abo', ['endpoint' => $endpoint, 'keys' => ['p256dh' => $uaPublic, 'auth' => $auth]])->assertStatus(422);
}
$this->postJson('/push/abo', ['endpoint' => 'https://fcm.googleapis.com/fcm/send/1', 'keys' => ['p256dh' => $uaPublic, 'auth' => $auth]])->assertOk();
$this->assertSame(1, PushSubscription::query()->where('user_id', $user->id)->count());
$user->notify(new PortalNotification('Beitrag freigegeben', '„Sommerfest“ ist online.', '/neuigkeiten/sommerfest'));
Queue::assertPushed(SendWebPush::class, fn (SendWebPush $job) => $job->userId === $user->id && $job->payload['url'] === '/neuigkeiten/sommerfest');
$this->deleteJson('/push/abo', ['endpoint' => 'https://push.example.org/send/1'])->assertOk();
$this->deleteJson('/push/abo', ['endpoint' => 'https://fcm.googleapis.com/fcm/send/1'])->assertOk();
$this->assertSame(0, PushSubscription::query()->count());
// Ohne Abonnement: nur die Glocke
@ -115,4 +119,13 @@ class WebPushTest extends TestCase
$this->assertSame(0, PushSubscription::query()->count());
}
public function test_foreign_subscriptions_cannot_be_taken_over(): void
{
[, $uaPublic, $auth] = $this->browserKeys();
$endpoint = 'https://fcm.googleapis.com/fcm/send/geraet-1';
$this->actingAs(User::factory()->create())->postJson('/push/abo', ['endpoint' => $endpoint, 'keys' => ['p256dh' => $uaPublic, 'auth' => $auth]])->assertOk();
$this->actingAs(User::factory()->create())->postJson('/push/abo', ['endpoint' => $endpoint, 'keys' => ['p256dh' => $uaPublic, 'auth' => $auth]])->assertStatus(409);
}
}

View file

@ -239,6 +239,19 @@ class PagesTest extends TestCase
$this->get($file['url'])->assertOk()->assertDownload('Urlaubsantrag 2027.pdf');
$this->actingAs(User::factory()->create(['department' => 'Küche']))->get($file['url'])->assertNotFound();
// Nicht eingebundene Datei (z. B. nur im Entwurf) und Datei in einem Block für andere: nicht abrufbar
$this->actingAs($this->admin);
$draftFile = $this->postJson('/redaktion/seiten/'.$page->id.'/dateien', ['file' => UploadedFile::fake()->create('Gehaltsliste.pdf', 10, 'application/pdf')])->json('file');
$this->actingAs($nurse)->get($draftFile['url'])->assertNotFound();
$hr = Role::query()->create(['name' => 'Personalabteilung']);
$this->actingAs($this->admin)->postJson('/redaktion/seiten/'.$page->id.'/veroeffentlichen', ['title' => 'Formulare', 'content' => ['blocks' => [
['type' => 'downloads', 'data' => ['files' => [$stored->id]]],
['type' => 'downloads', 'data' => ['files' => [PageFile::query()->where('name', 'Gehaltsliste.pdf')->value('id')]], 'visibility' => ['role' => [(string) $hr->id]]],
]]]);
$this->actingAs($nurse)->get($draftFile['url'])->assertNotFound();
$this->actingAs($nurse)->get($file['url'])->assertOk();
}
public function test_images_are_stored_as_webp(): void

View file

@ -0,0 +1,71 @@
<?php
namespace Tests\Feature\Permissions;
use App\Filament\Resources\Roles\Pages\EditRole;
use App\Filament\Resources\Users\Pages\EditUser;
use App\Models\Role;
use App\Models\User;
use App\Support\Permissions\Permissions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class PrivilegeEscalationTest extends TestCase
{
use RefreshDatabase;
private User $hr;
protected function setUp(): void
{
parent::setUp();
$role = Role::query()->create(['name' => 'Personal']);
$role->grants()->create(['ability' => 'users.manage']);
$role->grants()->create(['ability' => 'roles.manage']);
$this->hr = User::factory()->withRoles([$role])->create();
}
public function test_user_managers_cannot_grant_themselves_administration(): void
{
$this->actingAs($this->hr);
$admin = Role::administration();
Livewire::test(EditUser::class, ['record' => $this->hr->getRouteKey()])
->fillForm(['manual_roles' => [...$this->hr->roles()->pluck('roles.id')->all(), $admin->id]])
->call('save')
->assertHasFormErrors(['manual_roles']);
Permissions::flush();
$this->assertFalse($this->hr->fresh()->permissions()->isSuperuser());
}
public function test_user_managers_cannot_edit_or_delete_full_administrators(): void
{
$admin = User::factory()->admin()->create();
$this->assertFalse($this->hr->can('update', $admin));
$this->assertFalse($this->hr->can('delete', $admin));
$this->assertTrue($this->hr->can('update', User::factory()->create()));
$this->actingAs($this->hr)->get("/admin/benutzer/{$admin->id}/bearbeiten")->assertForbidden();
}
public function test_role_managers_cannot_add_rights_they_do_not_have(): void
{
$this->actingAs($this->hr);
$team = Role::query()->create(['name' => 'Team']);
Livewire::test(EditRole::class, ['record' => $team->getRouteKey()])
->fillForm(['global_abilities' => ['plugins.manage']])
->call('save')
->assertHasFormErrors(['global_abilities']);
Livewire::test(EditRole::class, ['record' => $team->getRouteKey()])
->fillForm(['global_abilities' => ['users.manage']])
->call('save')
->assertHasNoFormErrors();
$this->assertFalse($this->hr->can('update', Role::administration()));
}
}

View file

@ -8,6 +8,7 @@ use App\Plugins\PluginManager;
use App\Plugins\PluginManifest;
use App\Plugins\PluginState;
use App\Plugins\PluginUpdates;
use App\Support\SafeOutbound;
use App\Support\Update\Filesystem;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
@ -37,6 +38,7 @@ class PluginUpdatesTest extends TestCase
$manager = new PluginManager($this->app, new PluginState($this->dir.'/state.json'), $this->dir.'/core', $this->dir.'/custom');
$this->app->instance(PluginManager::class, $manager);
$this->app->forgetInstance(PluginUpdates::class);
SafeOutbound::fakeResolve(['git.example.org' => '93.184.216.34', 'x.test' => '93.184.216.34']);
}
protected function tearDown(): void

View file

@ -4,6 +4,8 @@ namespace Tests\Feature\Profile;
use App\Models\Role;
use App\Models\User;
use App\Support\ProfileFields;
use App\Support\Settings;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\TestCase;
@ -60,7 +62,7 @@ class ProfileTest extends TestCase
public function test_own_profile_can_be_updated(): void
{
$user = User::factory()->create();
$user = User::factory()->create(['department' => 'IT', 'location' => 'Bremen', 'email' => 'alt@example.com']);
$this->actingAs($user)
->put('/profil', [
@ -79,8 +81,17 @@ class ProfileTest extends TestCase
$user->refresh();
$this->assertSame('Grete Müller', $user->name);
$this->assertSame('MAV', $user->department);
$this->assertSame('grete@example.com', $user->email);
$this->assertSame('Mitarbeitervertretung', $user->job_title);
// Abteilung, Standort und E-Mail steuern Sichtbarkeit bzw. Anmeldung – nicht selbst änderbar
$this->assertSame('IT', $user->department);
$this->assertSame('Bremen', $user->location);
$this->assertSame('alt@example.com', $user->email);
// Freigabe durch die Administration: Abteilung und Standort, E-Mail weiterhin nicht
app(Settings::class)->set(ProfileFields::SELF_EDIT_ORG, true);
$this->put('/profil', ['first_name' => 'Grete', 'last_name' => 'Müller', 'department' => 'MAV', 'location' => 'Hamburg', 'email' => 'neu@example.com'])->assertSessionHasNoErrors();
$this->assertSame('MAV', $user->fresh()->department);
$this->assertSame('alt@example.com', $user->fresh()->email);
}
public function test_profile_update_cannot_change_account_flags(): void

View file

@ -0,0 +1,30 @@
<?php
namespace Tests\Feature\Search;
use App\Models\Role;
use App\Models\User;
use App\Pagebuilder\Content;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Inhaus\Plugins\Pages\Models\Page;
use Tests\TestCase;
class RestrictedBlocksSearchTest extends TestCase
{
use RefreshDatabase;
public function test_text_of_restricted_blocks_is_not_found_by_others(): void
{
$hr = Role::query()->create(['name' => 'Personalabteilung']);
$page = Page::query()->create(['title' => 'Personal']);
$page->publish('Personal', app(Content::class)->sanitize(['blocks' => [
['type' => 'heading', 'data' => ['text' => 'Allgemeine Hinweise']],
['type' => 'heading', 'data' => ['text' => 'Gehaltsbänder Geschäftsführung'], 'visibility' => ['role' => [(string) $hr->id]]],
]]), User::factory()->admin()->create());
$search = fn (User $user) => collect($this->actingAs($user)->getJson('/suche/live?q=Gehaltsbänder')->json('groups'))->flatMap(fn ($g) => $g['items'] ?? $g['results'] ?? [])->all();
$this->assertSame([], $search(User::factory()->create()));
$this->assertNotSame([], $search(User::factory()->withRoles([$hr])->create()));
}
}

View file

@ -5,6 +5,7 @@ namespace Tests\Feature\Stellen;
use App\Models\Role;
use App\Models\User;
use App\Notifications\PortalNotification;
use App\Plugins\PluginAccess;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Mail;
@ -177,4 +178,25 @@ class StellenTest extends TestCase
->where('posting.apply_mode', 'email')->where('posting.apply_email', 'bewerbung@firma.de')->where('canApply', false));
$this->post("/stellen/{$posting->id}/bewerben", ['message' => 'x'])->assertNotFound();
}
public function test_posting_editors_cannot_make_themselves_contact_to_read_applications(): void
{
$this->actingAs($this->hr)->post('/redaktion/stellen', [
'title' => 'Selbst', 'employment' => 'full', 'contract' => 'permanent', 'apply_mode' => 'online', 'publish' => 'draft', 'contact_id' => $this->hr->id,
])->assertSessionHasErrors('contact_id');
}
public function test_excluded_roles_are_not_notified_about_new_postings(): void
{
Notification::fake();
$external = Role::query()->create(['name' => 'Extern']);
app(PluginAccess::class)->exclude('stellen', [$external->id]);
$guest = User::factory()->withRoles([$external])->create();
$staff = User::factory()->create();
app(Announcer::class)->announceIfDue($this->posting());
Notification::assertSentTo($staff, PortalNotification::class);
Notification::assertNotSentTo($guest, PortalNotification::class);
}
}

View file

@ -3,6 +3,7 @@
namespace Tests\Feature\WordpressImport;
use App\Models\User;
use App\Support\SafeOutbound;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Http;
@ -33,6 +34,7 @@ class WordpressImportTest extends TestCase
$this->admin = User::factory()->admin()->create();
$png = UploadedFile::fake()->image('x.png', 40, 30)->getContent();
SafeOutbound::fakeResolve(['intranet.example.org' => '93.184.216.34']);
Http::fake([
'intranet.example.org/wp-content/uploads/*' => Http::response($png, 200, ['Content-Type' => 'image/png']),
'*' => Http::response('nicht da', 404),

View file

@ -0,0 +1,23 @@
<?php
namespace Tests\Unit;
use App\Support\SafeOutbound;
use PHPUnit\Framework\TestCase;
class SafeOutboundTest extends TestCase
{
public function test_internal_targets_are_rejected(): void
{
SafeOutbound::fakeResolve(['public.test' => '93.184.216.34', 'rebind.test' => ['93.184.216.34', '10.0.0.1']]);
$this->assertTrue(SafeOutbound::isPublicUrl('https://public.test/bild.jpg'));
$this->assertFalse(SafeOutbound::isPublicUrl('https://rebind.test/x'), 'eine interne Adresse genügt');
foreach (['http://127.0.0.1/', 'http://localhost/', 'http://10.1.2.3/', 'http://192.168.0.5/', 'http://169.254.169.254/latest/meta-data/', 'http://[::1]/', 'http://[fd00::1]/', 'ftp://public.test/', 'http://user@public.test/', 'https://intranet.local/', 'file:///etc/passwd', 'http://nichtaufloesbar.invalid/'] as $url) {
$this->assertFalse(SafeOutbound::isPublicUrl($url), $url);
}
$this->assertFalse(SafeOutbound::isPublicUrl('http://public.test/', ['https']), 'nur https erlaubt');
}
}