PHP code example of ruvelo / security-advisories

1. Go to this page and download the library: Download ruvelo/security-advisories 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 / security-advisories example snippets


use Ruvelo\SecurityAdvisories\{Reconciler, Scanner, Threshold};

$scanner = Scanner::forProject('/srv/app', cache: $psr16Cache);   // composer.lock, package-lock.json, CISA KEV
$report  = $scanner->scan();

foreach ($report->findings as $finding) {                         // exploited first, then by severity
    echo "{$finding->package} {$finding->installed}: {$finding->title}"
        .($finding->isExploited() ? ' (EXPLOITED)' : '')
        .($finding->fixedIn ? " -> {$finding->fixedIn}" : '')."\n";
}

if (! $report->isComplete()) {
    print_r($report->problems);                                   // "no findings" is not "clean" when this isn't empty
}

$reconciler = new Reconciler();
$changes = $reconciler->reconcile($known, $report, $lastSeen);   // $known: key => was exploited; $lastSeen: optional, see below
$changes->new;               // list<Finding>
$changes->exploited;         // list<Finding> that just became exploited
$changes->resolved;          // list<string> keys that are gone
$changes->resolvedFindings;  // key => Finding as last seen, for the keys you kept data for

$failed = [/* keys whose alert couldn't be delivered */];
$known    = $reconciler->next($known, $report, $failed);         // store this for next time; $failed stay news
$lastSeen = $reconciler->lastSeen($lastSeen, $report, $known);   // and this, to say more than a key when one resolves
exit($report->failsOn(Threshold::High) ? 1 : 0);

$scanner = Scanner::forProject('/srv/app', cache: $psr16Cache, source: 'public');

$scanner = new Scanner(
    [new ComposerLockReader($dir.'/composer.lock', evCatalogue(),
);

$scanner = Scanner::forProject(
    '/srv/shop',
    cache: $cache,
    ecosystems: [Ecosystem::Composer],                    // default: Composer and npm
    extraSources: [new FriendsOfPrestaSource(/* ... */)], // asked besides the built-in ones
    extraPackageSources: [new ExtensionList($modules)],   // read besides the lockfiles
);