Home

Awesome

This library is made available early; expect and please report bugs.

See the Function Samples repository for history of this project and other function examples.

Status

Status: Archived

This sample is no longer actively maintained and is left here for reference only.

Table of Contents

<a name="overview"></a> Project Overview

This library, created by Dan Zhang, contains a FirebaseCloud Function triggered by account deletion (an Auth.delete event) that wipes out all the data in the Firebase Realtime Database that belonged to the deleted user.

Compliance with privacy regulations requires that developers ensure that a user's data is deleted when they delete their account. To determine what data should be deleted, the Cloud Function analyzes the app's Security Rules and identifies any data that can only be written by a particular user.

For example, when a user authenticates, we may save personal data of the form:

/functions-project-12345
    /users
        $uid : "Some user data"

And when the user deletes their account a Function will automatically delete the corresponding user data in the realtime database.

This library also includes a simple demo app showing how the Function works.

<a name="implementation"></a> Implementation overview

See functions/wipeout.js for the data cleanup code.

When a user deletes their account, their data in the database will be deleted automatically according to Wipeout Rules that can either be

As it is, the function to wipeout user data is only triggered when a user deletes their account, but it would be straightforward to add also trigger the function via an admin console, given a user id.

Don't modify the WIPEOUT_CONFIG object in functions/index.js unless you know the code well.

Developer confirmation of the Wipeout Rules is needed before the function begins removing user data; see step 9 in Deploy and test for details.

Dependencies for this library are listed in functions/package.json.

<a name="test"></a> Deploy and test

This sample comes with a Function and web-based UI for testing the function. To configure it:

  1. Create a Firebase Project using the Firebase Console.
  2. Enable Google Auth. In the Firebase Console open the Authentication section > SIGN IN METHOD tab you need to enable the Google Sign-in Provider and click SAVE.
  3. Clone or download this repo and open the user-data-cleanup directory.
  4. You must have the Firebase CLI installed. If you don't have it install it with npm install -g firebase-tools and then configure it with firebase login.
  5. Configure the CLI locally by using firebase use --add and select your project in the list.
  6. Install dependencies locally by running: cd functions; npm install; cd -
  7. Run local tests using cd functions; npm test
  8. Deploy your project using firebase deploy, and note the showWipeoutConfig URL printed out.
  9. Visit the showWipeoutConfig URL in a browser and Initialized the library for this database by clicking the "INITIALIZE" button.
  10. Go to the showWipeoutConfig URL again to verify the wipeout rules. The webpage will show the source of these wipeout rules, either loaded from local config or generated from security rules.
  11. The format of wipeout rules are described in the next section. If the rules are correct, click the "CONFIRM DEPLOYMENT" button, or else change the local configuration file functions/wipeout_config.json and redeploy. Note a developer confirmation is required after every deployment.
  12. Open the app using firebase open hosting:site, this will open a browser.
  13. Sign in using Google Sign-In and delete the account using the provided button. You can check at each step of the way if the data has been deleted using the Firebase console.

<a name="wipeout-rules"></a> Understanding the wipeout rules

The path string can use variable $WIPEOUT_UID which will be replaced by UID of the deleted user account when triggered.

The Wipeout Rules are a JSON object with the top-level key "wipeout" the value of a list of JSON objects, each describing a pattern of user data storage. When a user account is deleted, the library goes through every Wipeout Rule to remove any data with these patterns for that user. A single config rule may have four fields:

Data reference: A String representing the value or existence of data at a location in the database. The String format is a call of val() or exists(), and the list of arguments stands for the path to the location. The root of the path is always 'rules'. e.g. val(rules,chat,$room,creator) stands for the value at location /chat/$room/creator.

At execution time, a config will go through the following process to get a set of materialized absolute paths in the database:

  1. Swap #WIPEOUT_UID place holder with auth.uid of deleted account.
  2. Evaluate condition, filter out any config with a false condition.
  3. Evaluate authVar, retrieve values for variables in path.
  4. Evaluate any exception clauses.
  5. Remove any remaining trailing free variables since they represent wildcard values in paths. After the removal, any path that still contains a free variable is not supported for deletion and will be ignored.

After these steps, we're left with a list of concrete data paths to delete. The library deletes the data and records the paths to the deleted data with a timestamp at /wipeout/history/#WIPEOUT_UID in the realtime database.

<a name="use"></a> How to add this library to your Firebase project

The following instructions are the instructions to install both the wipeout library and the demo app that lives in the public/ folder.

<a name="add-to-new"></a>

If you're creating a new project:

Continue with the rules for existing projects.

<a name="existing"></a>

To add this to existing projects:

<a name="contribute"></a> How to contribute

If you'd like to contribute to the library, or are just curious about how it is built, please see the overview Design Doc, the detailed explanation of Auto Rules Extraction.

Before contributing, review the contribution guidelines, including Code of Conduct it contains, and sign the Contributor License Agreement.


Released under the Apache License.

Disclaimer: This is not an official Google product.