xchimx/laravel-security
Composer 安装命令:
composer require xchimx/laravel-security
包简介
A Laravel package for automated monitoring of security vulnerabilities and outdated packages in Composer and NPM dependencies.
README 文档
README
A Laravel package for automated monitoring of security vulnerabilities and outdated packages in Composer and NPM dependencies.
Installation
You can install the package via composer:
composer require xchimx/laravel-security
You can publish and run the migrations with:
php artisan vendor:publish --tag="security-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="security-config"
You can publish the views, or you add this line to your app.css:
@source '../../../../vendor/xchimx/laravel-security/resources/views/**/*.blade.php';
Customize the config/security.php file according to your requirements or set the corresponding ENV variables:
# App Info APP_NAME=MyApp APP_URL=https://myapp.com # Security Audit SECURITY_AUDIT_ENABLED=true SECURITY_AUDIT_TIME=02:00 SECURITY_AUDIT_COMPOSER=true SECURITY_AUDIT_NPM=true # Outdated Checks SECURITY_OUTDATED_ENABLED=true SECURITY_OUTDATED_TIME=03:00 SECURITY_OUTDATED_COMPOSER=true SECURITY_OUTDATED_NPM=true # Notifications SECURITY_NOTIFY_USER_ID=1 SECURITY_NOTIFICATIONS_USER_MODEL=App\Models\User SECURITY_NOTIFICATIONS_ROUTE=admin.security SECURITY_NOTIFY_MAIL=true SECURITY_NOTIFY_DATABASE=true SECURITY_NOTIFY_DATABASE_MAIL=false SECURITY_NOTIFY_SLACK=false SECURITY_MAIL_TO=admin@example.com SLACK_BOT_USER_OAUTH_TOKEN=xxx-xxx-xxx SLACK_BOT_USER_DEFAULT_CHANNEL="#security-alerts"
Optionally, you can publish the views using
php artisan vendor:publish --tag="security-views"
Usage
The package automatically registers the following tasks in the Laravel Scheduler:
- Security Audit: Daily at 02:00 (configurable)
- Outdated Check: Weekly on Mondays at 3:00 a.m. (configurable)
Ensure that the Laravel Scheduler is running:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
Manual Usage
# Perform security audit php artisan security:audit # Check Composer only php artisan security:audit --composer # Check NPM only php artisan security:audit --npm # Check for outdated packages php artisan security:outdated # Check Composer only php artisan security:outdated --composer # Check NPM only php artisan security:outdated --npm
Dashboard Component
Integrate the Security Dashboard Component into your Blade views:
<x-security-security-dashboard />
Programmatic Access
use Xchimx\LaravelSecurity\Models\SecurityAudit; // Retrieve latest Composer audit $audit = SecurityAudit::getLatestAudit('composer'); // Latest outdated check for NPM $outdated = SecurityAudit::getLatestOutdated('npm'); // All audits with issuesen $issues = SecurityAudit::withIssues()->get(); // Audits from the last 7 days $recent = SecurityAudit::where('executed_at', '>=', now()->subDays(7))->get();
Notifications
Database notifications
Database notifications are sent to the user ID configured in SECURITY_NOTIFY_USER_ID. If the user has an email address and SECURITY_NOTIFY_DATABASE_MAIL is set to true, the notification is also sent to that address
When database notifications are enabled, notifications are stored in the notifications table. This requires the standard Laravel notifications migration:
SECURITY_NOTIFY_USER_ID=1 #User ID SECURITY_NOTIFICATIONS_USER_MODEL=App\Models\User #User Model SECURITY_NOTIFY_DATABASE=true #Set database notification to enabled SECURITY_NOTIFY_DATABASE_MAIL=false #User receives database notification without email. Set to “true” if an email should also be sent.
php artisan notifications:table php artisan migrate
Email notifications
Emails are sent to the address configured in SECURITY_MAIL_TO. You can separate multiple addresses with commas:
SECURITY_MAIL_TO=admin@example.com,security@example.com
Slack notifications
Configure your Slack token:
SECURITY_NOTIFY_SLACK=true SLACK_BOT_USER_OAUTH_TOKEN=xxx-xxx-xxx SLACK_BOT_USER_DEFAULT_CHANNEL="#security-alerts"
Data model
The security_audits table stores:
type: 'audit' or 'outdated'source: 'composer' or 'npm'results: JSON with details about the issues foundvulnerabilities_count: Number of security vulnerabilitiesoutdated_count: Number of outdated packageshas_issues: Boolean flagraw_output: Raw output of the commandexecuted_at: Time of execution
Requirements
- PHP ^8.3
- Laravel ^13.0
- Composer (installed on the server)
- NPM (Optional if NPM packages are to be checked)
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.
Views
xchimx/laravel-security 适用场景与选型建议
xchimx/laravel-security 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 366 次下载、GitHub Stars 达 9, 最近一次更新时间为 2026 年 01 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「composer」 「Audit」 「laravel」 「npm」 「Laravel-Security」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xchimx/laravel-security 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xchimx/laravel-security 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xchimx/laravel-security 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Log adding/updating/deleting of elements
Doctrine ORM provider for the auditor audit-log library.
Provide a way to secure accesses to all routes of an symfony application.
PB Web Media Audit Bundle for Symfony
It's a barebone security class written on PHP
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
统计信息
- 总下载量: 366
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 41
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-26




