idez/

nova-security

这是一个集合了多种技术和措施,以使您的laravel应用更加安全的包。


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

这是一个集合了多种技术和措施,以使您的laravel应用更加安全的包。

支持我们

发送邮件至 arthur@idez.com.brpedro@idez.com.br

安装

您可以通过composer安装此包

composer require idez/nova-security

您可以使用以下命令发布并运行迁移

php artisan vendor:publish --tag="nova-security-migrations"
php artisan migrate

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="nova-security-config"

您可以使用以下命令发布翻译文件

php artisan vendor:publish --tag="nova-security-translations"

您可以使用以下命令发布视图文件

php artisan vendor:publish --tag="nova-security-views"

这是发布配置文件的内容

return [
    'brute_force' => [
        'enabled' => true,
        'max_attempts' => 3,
        'ttl' => 3600,
        'protected_field' => 'email',
    ],


    '2fa' => [
        /**
         * Uses original config file for the 2fa.
         */
        'ignore_override' => false,

        /**
         * Require 2FA for all users.
         */
        'require_for_all' => false,

        //... Other settings are the same as the google2fa-laravel configuration file.
    ]
];

用法

暴力破解

暴力破解保护是一个中间件,可以注册到您的应用的 App\Http\Kernel

use Idez\NovaSecurity\Http\Middleware\NovaBruteForceProtection;
    'middleware' => [
        NovaBruteForceProtection::class
    ]

您可以将它放在其他地方,例如 App\Http\Kernelconfig/nova.php

双因素认证

此包使用 pragmarx/google2fa-laravel 包作为基础。

Google 2fa 或一次性密码是一个中间件,可以注册到您的应用的 config/nova.php

use Idez\NovaSecurity\Http\Middleware\NovaTwoFactor;
    'middleware' => [
        NovaTwoFactor::class
    ]

操作

在用户资源中

    \Idez\NovaSecurity\Actions\SetupUserTwoFactorAction::make()->onlyOnDetail()
        ->canSee(fn ($request) => $request instanceof ActionRequest || ($this->resource->id === auth()->user()->id && ! filled($this->resource->two_factor_secret)))
        ->canRun(fn ($request) => $request instanceof ActionRequest || ($this->resource->id === auth()->user()->id && ! filled($this->resource->two_factor_secret))),


    \Idez\NovaSecurity\Actions\UnblockUserAction::make()
        ->onlyOnDetail()
        ->canSee(fn () => $request->user()->isSuperAdmin()),

测试

composer test

变更日志

请参阅 CHANGELOG 了解最近更改的详细信息。

贡献

请参阅 CONTRIBUTING 了解详细信息。

安全漏洞

请审查 我们的安全策略 了解如何报告安全漏洞。

致谢

许可证

MIT许可证(MIT)。请参阅 许可证文件 了解更多信息。