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
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:
parent
a37895a16a
commit
f1202bea08
226 changed files with 1952 additions and 450 deletions
|
|
@ -2,15 +2,20 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Push\PushSubscription;
|
||||
use App\Support\Abilities;
|
||||
use App\Support\Audit;
|
||||
use App\Support\Avatars;
|
||||
use App\Support\Covers;
|
||||
use App\Support\Permissions\Permissions;
|
||||
use App\Support\Permissions\PermissionSet;
|
||||
use App\Support\ProfileFields;
|
||||
use App\Support\Settings;
|
||||
use Database\Factories\UserFactory;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Models\Contracts\HasAvatar;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Auth\Notifications\ResetPassword;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
|
@ -21,6 +26,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
|
|
@ -39,6 +46,24 @@ class User extends Authenticatable implements FilamentUser, HasAvatar
|
|||
|
||||
protected static function booted(): void
|
||||
{
|
||||
// Protokoll: Konten anlegen, ändern (ohne Werte von Passwörtern), löschen
|
||||
static::created(fn (User $user) => Audit::log('user.created', ['user' => $user->id, 'email' => $user->email]));
|
||||
static::deleted(fn (User $user) => Audit::log('user.deleted', ['user' => $user->id, 'email' => $user->email]));
|
||||
static::updated(function (User $user) {
|
||||
$changed = array_values(array_diff(array_keys($user->getChanges()), ['updated_at', 'remember_token', 'last_login_at', 'avatar_path', 'cover_path']));
|
||||
|
||||
if ($changed !== []) {
|
||||
Audit::log('user.updated', ['user' => $user->id, 'fields' => $changed, 'is_active' => $user->wasChanged('is_active') ? $user->is_active : null]);
|
||||
}
|
||||
});
|
||||
|
||||
// Deaktiviert: alle Zugänge sofort beenden (Sitzungen, „Angemeldet bleiben“, API, Push)
|
||||
static::updated(function (User $user) {
|
||||
if ($user->wasChanged('is_active') && ! $user->is_active) {
|
||||
$user->revokeAccess();
|
||||
}
|
||||
});
|
||||
|
||||
// Der Anzeigename folgt Vor- und Nachname, solange beide gepflegt sind.
|
||||
static::saving(function (User $user): void {
|
||||
$fullName = trim($user->first_name.' '.$user->last_name);
|
||||
|
|
@ -121,6 +146,20 @@ class User extends Authenticatable implements FilamentUser, HasAvatar
|
|||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
/**
|
||||
* Felder, die die Person im Profil nicht selbst ändern darf: vom Anmeldedienst gepflegte,
|
||||
* die E-Mail-Adresse (Anmeldung, Verknüpfung, IT-Service) und – solange nicht freigegeben –
|
||||
* Abteilung und Standort, weil sie bestimmen, wer welche Inhalte sieht.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public function lockedProfileFields(): array
|
||||
{
|
||||
$selfOrg = (bool) app(Settings::class)->get(ProfileFields::SELF_EDIT_ORG, false);
|
||||
|
||||
return array_values(array_unique([...$this->managedFields(), 'email', ...($selfOrg ? [] : ['department', 'location'])]));
|
||||
}
|
||||
|
||||
public function managedFields(): array
|
||||
{
|
||||
return $this->identities()->with('provider')->get()
|
||||
|
|
@ -165,6 +204,10 @@ class User extends Authenticatable implements FilamentUser, HasAvatar
|
|||
$this->roles()->attach($roleId, ['source' => 'manual', 'created_at' => now()]);
|
||||
}
|
||||
|
||||
if (array_diff($roleIds, $current) || array_diff($current, $roleIds)) {
|
||||
Audit::log('user.roles_changed', ['user' => $this->id, 'added' => array_values(array_diff($roleIds, $current)), 'removed' => array_values(array_diff($current, $roleIds))]);
|
||||
}
|
||||
|
||||
Permissions::flush();
|
||||
}
|
||||
|
||||
|
|
@ -205,4 +248,33 @@ class User extends Authenticatable implements FilamentUser, HasAvatar
|
|||
{
|
||||
$query->where('is_active', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alle bestehenden Zugänge beenden: Sitzungen, „Angemeldet bleiben“, API-Tokens, Push-Abos.
|
||||
*/
|
||||
public function revokeAccess(bool $keepCurrentSession = false): void
|
||||
{
|
||||
$this->forceFill(['remember_token' => Str::random(60)])->saveQuietly();
|
||||
$this->tokens()->delete();
|
||||
PushSubscription::query()->where('user_id', $this->id)->delete();
|
||||
|
||||
if (Schema::hasTable(config('session.table', 'sessions'))) {
|
||||
DB::table(config('session.table', 'sessions'))->where('user_id', $this->id)
|
||||
->when($keepCurrentSession && session()->isStarted(), fn ($q) => $q->where('id', '!=', session()->getId()))
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Keine Reset-Mail für deaktivierte Konten und für Konten, die sich nur über
|
||||
* einen Anmeldedienst anmelden (sie sollen kein lokales Passwort bekommen).
|
||||
*/
|
||||
public function sendPasswordResetNotification(#[\SensitiveParameter] $token): void
|
||||
{
|
||||
if (! $this->is_active || ($this->password === null && $this->identities()->exists())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->notify(new ResetPassword($token));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue