duality-studio/lara-security 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

duality-studio/lara-security

Composer 安装命令:

composer require duality-studio/lara-security

包简介

A straight implementation of security headers for Laravel

README 文档

README

Simple way to add various security headers to a Laravel application.

This project is WIP and could with cleanup, better implementation and some docs.

Docs

TODO, the bellow is 5 minute notes.

Install

composer require duality-studio/lara-security

php artisan vendor:publish --provider="DualityStudio\LaraSecurity\LaraSecurityServiceProvider"

In your app/Http/Kernel.php add the following to the $middleware array or as you see fit.

\DualityStudio\LaraSecurity\SecurityHeaders::class,

In your config/lara-security.php you can configure the headers you want to use, all are enabled by default. In the CSP header is broken into directives.

Nonces

If you intend to use a nonce in your you will need to add a script or style directive for your static files.

<script @nonce(\DualityStudio\LaraSecurity\Directives::SCRIPT)>
    window.addEventListener('load', function () {
        console.log(1);
    });
</script>
<style @nonce(\DualityStudio\LaraSecurity\Directives::STYLE)>
    body {
        background: #fff;
    }
</style>

Usage with Vite

Set use_vite to true in the config file. This will automatically add the nonce to the script and style tags in the vite manifest.

Usage of the package is problematic when using the vite dev server, so you can disable the package when in dev mode by adding the following to your .env

LARA_SECURITY_ENABLED=false

Usage with Inertia.JS

If you are using Inertia.JS you will need to add the following to your app.blade.php file.

<!-- Scripts -->
@routes(null, nonce(\DualityStudio\LaraSecurity\Directives::SCRIPT))
@viteReactRefresh
@vite(['resources/js/app.jsx', "resources/js/Pages/{$page['component']}.jsx"])
@inertiaHead

统计信息

  • 总下载量: 1.15k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固