Giter VIP home page Giter VIP logo

laravel-gdpr's Introduction

GDPR compliance with ease

Scrutinizer Code Quality Latest Stable Version Monthly Downloads License

This package exposes an endpoint where authenticated users can download their data as required by GDPR article 20. This package also provides you with a trait to easily encrypt personal data and a strategy to clean up inactive users as required by GDPR article 5e.

Buy me a coffee โ˜•๏ธ

Requirements

  • PHP 7.0 or higher
  • Laravel 5.5+ (6.0, 7.0, 8.0)

Installation

First, install the package via the Composer package manager:

$ composer require soved/laravel-gdpr

After installing the package, you should publish the configuration file:

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

Finally, add the Soved\Laravel\Gdpr\Portable trait to the App\User model and implement the Soved\Laravel\Gdpr\Contracts\Portable contract:

<?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;
}

Configuration

Configuring Portable Data

By default, the entire toArray form of the App\User model will be made available for download. If you would like to customize the downloadable data, you may override the toPortableArray() method on the model:

<?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;
    }
}

Lazy Eager Loading Relationships

You may need to include a relationship in the data that will be made available for download. To do so, add a $gdprWith property to your App\User model:

<?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'];
}

Hiding Attributes

You may wish to limit the attributes, such as passwords, that are included in the downloadable data. To do so, add a $gdprHidden property to your App\User model:

<?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'];
}

Alternatively, you may use the $gdprVisible property to define a white-list of attributes that should be included in the data that will be made available for download. All other attributes will be hidden when the model is converted:

<?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'];
}

Usage

This package exposes an endpoint at /gdpr/download. Only authenticated users should be able to access the routes. Your application should make a POST call, containing the currently authenticated user's password, to this endpoint. The re-authentication is needed to prevent information leakage.

You may listen for the Soved\Laravel\Gdpr\Events\GdprDownloaded event, which will be dispatched upon successful re-authentication and data conversion.

Encryption

Before using encryption, you must set a key option in your config/app.php configuration file. If this value is not properly set, all encrypted values will be insecure.

You may encrypt/decrypt attributes on the fly using the Soved\Laravel\Gdpr\EncryptsAttributes trait on any model. The trait expects the $encrypted property to be filled with attribute keys:

<?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'];
}

Data Retention

You may clean up inactive users using the gdpr:cleanup command. Schedule the command to run every day at midnight, or run it yourself. In order for this to work, add the Soved\Laravel\Gdpr\Retentionable trait to the App\User model:

<?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;
}

You may listen for the Soved\Laravel\Gdpr\Events\GdprInactiveUser event to notify your users about their inactivity, which will be dispatched two weeks before deletion. The Soved\Laravel\Gdpr\Events\GdprInactiveUserDeleted event will be dispatched upon deletion.

Feel free to customize what happens to inactive users by creating your own cleanup strategy.

Roadmap

  • Tests

Security Vulnerabilities

If you discover a security vulnerability within this project, please send an e-mail to Sander de Vos via [email protected]. All security vulnerabilities will be promptly addressed.

License

This package is open-source software licensed under the MIT license.

laravel-gdpr's People

Contributors

ferranfg avatar laravel-shift avatar prattcmp avatar sander3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-gdpr's Issues

Retrieving Relationships from Direct Relationships

Given that a User has a relationship with Restaurant, and Restaurant has many MenuItems, how are we able to retrieve the MenuItems for that Restaurant?

I have tried making Restaurant Portable and defining with $gdprWith for that model, but that does not work.

As well, it appears as though all properties on a model with a relationship (Restaurant in this case) will be visible, regardless of making the Restaurant model Portable and assigning $gdprVisible property to exclude things like id, hash, etc. Will be opening a separate bug for this.

Unable to install via Composer

When attempting to run composer require soved/laravel-gdpr, I'm getting an error saying that the operation failed because the packagist json file for this package couldn't be found.

[Composer\Downloader\TransportException]                                                                                                                                       
  The "http://packagist.org/p/soved/laravel-gdpr%241e01b0addbc1e9551aefb73142b21f1a1c80109f7db96f8b112a589e5efd66e2.json" file could not be downloaded (HTTP/1.1 404 Not Found) 

This may be an issue on my end, but while I investigate I thought I would bring it to your attention so you can look into this.

Thanks.

API data decryption

Hi,
I have stored some encrypted data in my db.
Now I need to create API, but all values return encrypted.
Is there a way to decrypt data?

Thank you

How to hide relation attributes?

Hi, I am not able to hide specific attributes from relations. I have tried the following:

  1. in User set $gdprHidden = ['relation.attribute']

  2. Add Portable trait to Relation and inside it set $gdprHidden = ['attribute']

What am I missing? Thank you.

show only some relationship attributes

Hello,

Thanks for this great package !

I tried to hide some of the relationship attributes by using your $gdprVisible property with just the fields I want visible, working ok for the User model but not for the relationships.
(I tried to add some of the relationship attributes like 'bookings.name' in $gdprVisible, but it's not working)

Anyway to do that ?
Thanks, Denis

Decryption not working with toArray()

Hi there,

Automatic decryption of values only works when accessing model attributes like this:
$model->attribute

However, returning a model instance or using $model->toArray() returns encrypted values.

Any suggestions?

usage doubt

Hello,

I'm newbie in laravel and sure that the problem is that I dont know how to use.
I've installed the package and make a get web url endpoint that execute a post API call to /gdpr/download endpoint.

Route::get('/gdpr', function () { $response = Http::post('http://mywebpage.test/gdpr/download', [ Auth::user()->password, ]); dd($response); });

I've dd the response and status 200 is returned but no data :(

Could please help me? Thanks a lot.

How to use this with Socialite?

If a user has to enter a password to download their data, how do plan (if not already) to handle the case where a user signed up via Facebook or other OAuth service? In most of these cases, a password will not be set for the user, or a randomly generated password will be set at the time of account creation.

Authentication Mistake

Hi Guys

I have some error when I try to get user by email

Have settings below

use EncryptsAttributes

protected $encrypted = [ 'email'];

I made query User::where(['email' => '[email protected]'])->first();

It doesn't wwork

Remove package generates odd messages

when removing the package via composer you get the following messages:

soved/laravel-gdpr is not required in your composer.json and has not been removed
Dependency "laravel/framework" is also a root requirement, but is not explicitly whitelisted. Ignoring.

It's odd to get a message about removing laravel framework ?

How to encrypt existing data?

Data encryption works just fine on newer inserted data.
But how can I apply the encryption on already existing data?

Also, what data type should I use for encrypted columns?

Retrieve decrypted attribute through request

How am I able to retrieve the encrypted attribute decrypted through the HTTP request user object?

Like so: $request->user();

Currently I noticed that I just retrieve the not decrypted attribute.

Regarding GDPR

Question received via email.

Hi,
We have added  https://github.com/sander3/laravel-gdpr this package in a local  project. Can you tell me how to test  to verify the install successfully  ?.
-- 
Thanks & Regards
Ashutosh *****
Mob No:- **********

All Properties of Model are Visible when using $gdprVisible

In my User model I have protected $gdprVisible = ['name', 'email'];, yet in the JSON output I see

{"id":22,"name":"John Doe","email":"[email protected]","created_at":"2018-07-09 14:52:02","updated_at":"2018-07-09 14:52:02","stripe_id":null,"card_brand":null,"card_last_four":null,"trial_ends_at":null,"provider":null,"provider_id":null}

The docs say that anything NOT in the white-list will be hidden, but I don't see this as being the case.

Also, any models included via relationship are also displaying their entire contents.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.