mydevnl / audit-routes
深入了解您Laravel路由的安全性和保护。Audit Routes是您保持应用程序稳固的新最佳拍档!
Requires
- php: ^8.0
- illuminate/console: ^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/filesystem: ^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/routing: ^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^7.0|^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- nikic/php-parser: ^5.1
- phpunit/phpunit: ^11.3
Suggests
- irazasyed/larasupport: Needed to publish the package configuration in Lumen
This package is auto-updated.
Last update: 2024-09-26 22:14:29 UTC
README
此PHP包提供了一种简化方法来深入了解您应用程序路由的安全性和保护。只需几秒钟,您就可以评估以下关键方面:
- 测试覆盖率:确保您的所有路由都有测试覆盖率
- 身份验证:检查哪些路由需要身份验证
- 权限:验证是否设置了权限或策略检查
- 中间件:确认已应用必要的中间件
Audit Routes是您保持应用程序稳固的新最佳拍档!发现潜在缺陷现在比以往任何时候都更快、更容易。
支持Laravel和其他框架
此包是为Laravel构建的,将支持即将到来的Symfony,并设计为可扩展,以便与其他PHP框架一起使用,让您能够在各种框架中利用其强大的功能。
安装
您可以通过Composer安装此包
composer require mydevnl/audit-routes:dev-main --dev
安装后,只需运行route:audit
命令
php artisan route:audit -vvv
可选地发布配置文件
php artisan vendor:publish --tag=audit-routes-config
使用方法
安装后,设置自定义命令变得轻而易举。该包提供灵活的选项,允许您根据应用程序的特定需求定制路由审计。为了帮助您开始,已包含一个默认命令来演示如何有效地利用这些选项。
AuditRoutes::for($this->router->getRoutes()->getRoutes()) ->setBenchmark(1000) ->run([ PolicyAuditor::class => 100, PermissionAuditor::class => -100, TestAuditor::make()->setWeight(250)->setPenalty(-10000)->setLimit(2333), MiddlewareAuditor::make(['auth']) ->ignoreRoutes(['login', 'password*', 'api.*']) ->setPenalty(-1000) ->setWeight(10), MiddlewareAuditor::make(['auth:sanctum']) ->when(fn (RouteInterface $route): bool => str_starts_with($route->getIdentifier(), 'api')) ->ignoreRoutes(['api.password', 'api.login', 'api.register']) ->setPenalty(-1000) ->setWeight(10), ]);
测试
该包附带内置断言,您可以通过使用AssertsAuditRoutes
特质在PHPUnit中运行路由安全性检查和审计合规性。这允许您将路由安全性检查和审计合规性作为持续集成管道的一部分。注意,Pest支持将在不久的将来添加。
一些示例
// Assert that all routes, or a specified array of routes, are covered in tests. $this->assertRoutesAreTested(['*']); // Assert a specific route to be covered in tests. $this->assertRouteIsTested('welcome'); // Assert that multiple routes are implemented with the specified middleware, while allowing certain routes to be excluded. $this->assertRoutesHaveMiddleware(['*'], ['auth'], ignoredRoutes: ['welcome', 'api.*']); // Assert that a specific route is implemented with the specified middleware. $this->assertRouteHasMiddleware('api.user.index', ['auth:sanctum']); // Ensure that all specified routes return an OK status when evaluated with custom auditors. $this->assertAuditRoutesOk($routes, [PolicyAuditor::make()], $message, benchmark: 1); // Use negative weight to assert that custom auditors are not applied to given routes. $this->assertAuditRoutesOk(['*'], [PermissionAuditor::make()->setWeight(-1)], $message);
贡献
我们欢迎对此项目的贡献!如果您有改进的想法或发现错误,请将其作为GitHub上的问题提交。贡献应基于标记为“已接受修复”的问题。我们非常重视并鼓励社区参与。
对于额外的帮助或问题,请通过GitHub问题进行联系。
安全漏洞
如果您发现任何安全漏洞,请立即报告。所有与安全相关的问题都将得到最高优先级处理。
许可
此包是开源软件,根据MIT许可证许可。
我们仍在开发中
请注意,最新版本是实验性的,可能不稳定。路线图将很快发布。关注mydevnl以保持最新状态!
愿您的代码完美无瑕!🎉