mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2026-02-04 15:53:17 +00:00
✨ Add Security Monitoring System with Command, Model, and Service
- 🛡️ Introduce `SecurityMonitor` service for tampering and malicious activity detection. - 🏷️ Add `SecurityAttempt` model and migration to log, categorize, and query security attempts. - 🖥️ Create `SecurityAttemptsCommand` for filtering, statistics, and top IP analysis. - ✅ Add extensive tests to ensure the reliability of security monitoring and logging. - 🔗 Integrate `SecurityMonitor` into the exception handling pipeline for real-time monitoring.
This commit is contained in:
50
app/Models/SecurityAttempt.php
Normal file
50
app/Models/SecurityAttempt.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SecurityAttempt extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'ip_address',
|
||||
'user_agent',
|
||||
'method',
|
||||
'url',
|
||||
'route_name',
|
||||
'exception_class',
|
||||
'exception_message',
|
||||
'component_name',
|
||||
'target_property',
|
||||
'payload',
|
||||
'severity',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'payload' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function scopeFromIp(Builder $query, string $ip): Builder
|
||||
{
|
||||
return $query->where('ip_address', $ip);
|
||||
}
|
||||
|
||||
public function scopeSeverity(Builder $query, string $severity): Builder
|
||||
{
|
||||
return $query->where('severity', $severity);
|
||||
}
|
||||
|
||||
public function scopeRecent(Builder $query, int $hours = 24): Builder
|
||||
{
|
||||
return $query->where('created_at', '>=', now()->subHours($hours));
|
||||
}
|
||||
|
||||
public function scopeForComponent(Builder $query, string $component): Builder
|
||||
{
|
||||
return $query->where('component_name', $component);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user