soved/laravel-gdpr

轻松实现GDPR合规性

v1.8.0 2024-03-25 13:41 UTC

This package is auto-updated.

Last update: 2024-09-25 14:41:49 UTC


README

Scrutinizer Code Quality Latest Stable Version Monthly Downloads License

此包提供了一个端点,认证用户可以下载他们的数据,以满足GDPR第20条的要求。此包还为您提供了一个特质,以便轻松加密个人数据,并提供了符合GDPR第5e条要求的清理不活跃用户的策略。

给我买杯咖啡 ☕️

要求

  • PHP 7.0或更高版本
  • Laravel 5.5+ (6.0, 7.0, 8.0)

安装

首先,通过Composer包管理器安装此包

$ composer require soved/laravel-gdpr

安装包后,您应该发布配置文件

$ php artisan vendor:publish --tag=gdpr-config

最后,将Soved\Laravel\Gdpr\Portable特质添加到App\User模型中,并实现Soved\Laravel\Gdpr\Contracts\Portable契约

<?php

namespace App;

use Soved\Laravel\Gdpr\Portable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Soved\Laravel\Gdpr\Contracts\Portable as PortableContract;

class User extends Authenticatable implements PortableContract
{
    use Portable, Notifiable;
}

配置

配置可携带数据

默认情况下,App\User模型的整个toArray形式将可用于下载。如果您想自定义可下载的数据,您可以在模型中重写toPortableArray()方法

<?php

namespace App;

use Soved\Laravel\Gdpr\Portable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Portable, Notifiable;

    /**
     * Get the GDPR compliant data portability array for the model.
     *
     * @return array
     */
    public function toPortableArray()
    {
        $array = $this->toArray();

        // Customize array...

        return $array;
    }
}

懒加载和预加载关系

您可能需要在将提供下载的数据中包含一个关系。为此,在您的App\User模型中添加一个$gdprWith属性

<?php

namespace App;

use Soved\Laravel\Gdpr\Portable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Portable, Notifiable;

    /**
     * The relations to include in the downloadable data.
     *
     * @var array
     */
    protected $gdprWith = ['posts'];
}

隐藏属性

您可能希望限制包含在可下载数据中的属性,例如密码。为此,在您的App\User模型中添加一个$gdprHidden属性

<?php

namespace App;

use Soved\Laravel\Gdpr\Portable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Portable, Notifiable;

    /**
     * The attributes that should be hidden for the downloadable data.
     *
     * @var array
     */
    protected $gdprHidden = ['password'];
}

或者,您可以使用$gdprVisible属性来定义应包含在可下载数据中的属性白名单。当模型转换时,所有其他属性都将被隐藏

<?php

namespace App;

use Soved\Laravel\Gdpr\Portable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Portable, Notifiable;

    /**
     * The attributes that should be visible in the downloadable data.
     *
     * @var array
     */
    protected $gdprVisible = ['name', 'email'];
}

用法

此包在/gdpr/download处公开了一个端点。只有认证用户应该能够访问这些路由。您的应用程序应该向此端点发送一个POST调用,其中包含当前认证用户的密码。重新认证是为了防止信息泄露。

您可以为成功重新认证和数据转换后分发的GdprDownloaded事件监听。

加密

在使用加密之前,您必须在您的config/app.php配置文件中设置一个key选项。如果此值未正确设置,所有加密值将是不安全的。

您可以使用任何模型上的Soved\Laravel\Gdpr\EncryptsAttributes特质来动态加密/解密属性。特质期望$encrypted属性填充有属性键

<?php

namespace App;

use Soved\Laravel\Gdpr\Portable;
use Illuminate\Notifications\Notifiable;
use Soved\Laravel\Gdpr\EncryptsAttributes;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use EncryptsAttributes, Portable, Notifiable;

    /**
     * The attributes that should be encrypted and decrypted on the fly.
     *
     * @var array
     */
    protected $encrypted = ['ssnumber'];
}

数据保留

您可以使用gdpr:cleanup命令清理不活跃用户。每天午夜运行此命令或自行运行。为了使其正常工作,请将Soved\Laravel\Gdpr\Retentionable特质添加到App\User模型中

<?php

namespace App;

use Soved\Laravel\Gdpr\Portable;
use Soved\Laravel\Gdpr\Retentionable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Retentionable, Portable, Notifiable;
}

您可以监听在删除前两周分发的GdprInactiveUser事件来通知您的用户他们的不活跃状态。在删除时将分发GdprInactiveUserDeleted事件。

您可以自由地通过创建自己的清理策略来自定义不活跃用户将发生什么。

路线图

  • 测试

安全漏洞

如果您在此项目中发现安全漏洞,请通过以下邮箱发送邮件至Sander de Vos:sander@tutanota.de。所有安全漏洞都将得到及时处理。

许可协议

本软件包是开源软件,受MIT许可证的许可。