skyraptor/laravel-gdpr

轻松实现GDPR合规

1.5.5 2020-09-09 21:06 UTC

This package is not auto-updated.

Last update: 2024-09-20 15:03:39 UTC


README

Scrutinizer Code Quality Latest Stable Version Monthly Downloads License

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

要求

  • PHP >= 7.0.0
  • Laravel >= 5.5或6.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调用。重新认证是为了防止信息泄露。

您可以监听Soved\Laravel\Gdpr\Events\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;
}

您可以通过监听Soved\Laravel\Gdpr\Events\GdprInactiveUser事件来通知您的用户关于他们的不活跃状态,该事件将在删除前两周触发。Soved\Laravel\Gdpr\Events\GdprInactiveUserDeleted事件将在删除时触发。

请自由创建自己的清理策略,以自定义不活跃用户的行为。

路线图

  • 测试

安全漏洞

如果在项目中发现安全漏洞,请通过sander@tutanota.de向Sander de Vos发送电子邮件。所有安全漏洞都将得到及时处理。

许可证

此软件包是开源软件,根据MIT许可证授权。