PHP code example of ruvelo / laravel-security-alerts

1. Go to this page and download the library: Download ruvelo/laravel-security-alerts library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ruvelo / laravel-security-alerts example snippets


use Ruvelo\SecurityAlerts\SecurityAlerts;

$report = SecurityAlerts::scan();       // what's vulnerable now; saves and sends nothing
$report->findings;                      // list<Finding>, exploited first, then by severity
$report->exploited();                   // the ones in CISA's catalogue
$report->counts();                      // ['exploited' => 1, 'critical' => 2, 'high' => 4, ...]
$report->isComplete();                  // false if a lockfile or feed failed; see $report->problems

$result = SecurityAlerts::check();      // scan, remember, fire events, send one notification
$result->found;                         // new SecurityAlert models
$result->exploited;                     // newly known to be exploited
$result->resolved;                      // no longer installed

SecurityAlerts::open();                 // open alerts, worst first, from the database: no network
SecurityAlerts::lastCheck();            // ['checked_at' => CarbonImmutable, 'findings' => 13, ...] or null
SecurityAlerts::sendDigest();           // the weekly digest, now

// AppServiceProvider::boot(): also notify your admins, through notify.via
SecurityAlerts::notifyUsing(fn () => User::where('is_admin', true)->get());

Event::listen(VulnerabilityExploited::class, fn ($event) => Incident::open("Patch {$event->alert->package} today"));

use Ruvelo\SecurityAlerts\Integrations\Health\SecurityAlertsCheck;

Health::checks([
    SecurityAlertsCheck::new(),                       // fails on exploited, warns from high
    // ->warnFrom('medium')->failFrom('critical')->staleAfterHours(48)
]);

use Ruvelo\SecurityAlerts\Models\SecurityAlert;

SecurityAlert::factory()->exploited()->forPackage('livewire/livewire', '3.6.2')->create();
SecurityAlert::factory()->severity(Severity::High)->create();
SecurityAlert::factory()->resolved()->create();
SecurityAlert::factory()->pending()->create();   // not yet sent

composer san migrate
echo "[email protected]" >> .env

php artisan security-alerts:check
yaml
- run: php artisan security-alerts:check --fail-on=exploited

php artisan vendor:publish --tag=security-alerts-config

php artisan vendor:publish --tag=security-alerts-views