How to handle PII in websites and web apps
Tags: featuredposts, security
Published: 2020-04-10 15:10:52

---
title: How to handle PII in websites and web apps
published: true
date: 2020-03-18 13:00:16 UTC
tags: Featured Posts,security
canonical_url: https://blog.logrocket.com/how-to-handle-pii-websites-web-apps/
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/y6wb0kxu40z6wyfw2bad.jpg
---
**Written by [Danny Guo](https://blog.logrocket.com/author/dannyguo/)**✏️

Many websites collect and store [personally identifiable information](https://en.wikipedia.org/wiki/Personal_data) (PII) in their normal course of business, and unfortunately, there are numerous ways that collected PII can be compromised. When this happens, the website’s users are exposed to personal risks, the website’s reputation is damaged, and the site owners can face serious legal and financial consequences.

## The importance of PII

PII is information tied to a particular individual or that can be used to identify them. Some common examples are:

- Name
- Address
- Telephone number
- Gender
- Date of birth
- Social Security number
- Driver’s license number
- Passport number

This sort of information can be stolen to facilitate identity theft, an increasingly common crime. In 2018, the FTC [estimated](https://www.thebalance.com/identity-theft-crimes-by-the-numbers-4157714) that over 444,000 people filed identity theft reports, and the most common type of identity theft was credit card fraud.

You can think of a set of PII as a key to people’s personal lives. By giving you their PII, your users are entrusting you to take care of it.

In many cases, there is a legal requirement to do so. For example, the [General Data Protection Regulation](https://en.wikipedia.org/wiki/General_Data_Protection_Regulation) (GDPR), the [California Consumer Protection Act](http://California%20Consumer%20Privacy%20Act) (CCPA), and the [Health Insurance Portability and Accountability Act](http://Health%20Insurance%20Portability%20and%20Accountability%20Act) (HIPAA) all provide rules for how companies need to treat personal data.

[![LogRocket Free Trial Banner](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2017/03/f760c-1gpjapknnuyhu8esa3z0jga.png?resize=1200%2C280&ssl=1)](https://logrocket.com/signup/)

## Data breaches

Companies generally place great value on the data they’ve collected; some have even referred to data as “[the new oil](https://www.quora.com/Who-should-get-credit-for-the-quote-data-is-the-new-oil).” Yet it’s increasingly being viewed more as a [liability](https://disruptionhub.com/david-carboni-data-was-asset-now-liability/). One lapse in security can lead to a bulk loss of PII, which is frequently accompanied by a negative news headline. Consider Equifax’s data breach, which led to weeks of [press coverage](https://www.nytimes.com/interactive/2017/your-money/equifax-data-breach-credit.html) and ultimately a $650 million [fine](https://www.nytimes.com/2019/07/22/business/equifax-settlement.html).

Data breaches have become so common that security expert [Troy Hunt](https://www.troyhunt.com/) set up a service called [Have I Been Pwned](https://haveibeenpwned.com/), which keeps track of breaches and lets people check whether their email address and personal information is included.

## Protecting PII

To avoid being one of those websites that have lost data, let’s consider possible attack vectors and how we can guard against them. Keep in mind that like other aspects of security, it only takes one failure point for PII to be lost. The best way to avoid leaking PII is to avoid collecting it in the first place. Nevertheless, collecting some PII is crucial to many websites.

Some of the following advice will overlap with the usual security practices best practices, but in general, we want to think about how PII is collected, transported, stored, and accessed.

Also keep in mind that the importance of information is relative. Take inventory of all the data that you collect and classify it according to its sensitivity. A Social Security number warrants more protection than a phone number.

### Use HTTPS

Essentially [all websites](https://www.troyhunt.com/heres-why-your-static-website-needs-https/) should be using [HTTPS](https://en.wikipedia.org/wiki/HTTPS) by now. By encrypting the connection between the website and the server, we can prevent third parties from intercepting the communications and reading what is being sent, including submitted data like PII in form fields.

[Let’s Encrypt](https://letsencrypt.org/) provides free TLS certificates, making it affordable to set this up, and which provide a line of defense against [man-in-the middle](https://en.wikipedia.org/wiki/Man-in-the-middle_attack) attacks.

### Hide info on the screen

You may want to prevent some information from being displayed all the time. The point of this is to prevent other people from seeing your users’ info just by looking at their screen. For example, you can set an input’s type to `“password”`:

```jsx
<input type="password">
```

This will result in an input field that replaces what the user types with asterisks. You can do similar things for other data, such as masking a Social Security number so that it is displayed as `XXX-XX-XXX` after the user enters it.

### Third-party services

When you integrate third-party services, it’s important to be aware of the data that you are sending them. If you send it indiscriminately, you are bound to send PII at some point. Google Analytics has a [list of suggestions](https://support.google.com/analytics/answer/6366371?hl=en) for avoiding sending PII.

If you use a UI recording tool, you’ll want to carefully think about what information should be hidden. For example, LogRocket provides [privacy mechanisms](https://docs.logrocket.com/docs/privacy) to easily filter the data that is transferred, including a way to [identify PII fields](https://docs.logrocket.com/docs/security#section-tools-to-block-pii) so that their values aren’t sent.

### Logging

Think about how your logging is set up and how the logs are stored. For example, if you log every request to your server, it’d be easy for something like a user’s Social Security number to end up in your logs in plaintext. Set up filters to keep this from happening.

### Storage

Be particularly careful when storing PII in a object storage system like [AWS S3](https://aws.amazon.com/s3/). S3 buckets are frequently [accidentally exposed](https://github.com/nagwww/s3-leaks) to the public. It’s good practice to default to [explicitly blocking public access](https://docs.aws.amazon.com/AmazonS3/latest/dev/access-control-block-public-access.html) for buckets.

### Encryption

Depending on the sensitivity of particular information, you may want to encrypt it at rest. This means that even if a hacker was able to obtain a copy of your database, the encrypted information will be protected if they weren’t able to steal the encryption key as well.

### Employee access

Consider what employees can access what information. Ideally, you’ll have a permissioning system so that employees are blocked from accessing information without a legitimate business reason. You may also want to implement an auditing system so that you know who accessed what information and when.

Doing this well means coming up with a data access policy and making sure employees are trained to understand it. You also need to make sure they are complying with it after the fact.

Facebook, for example, [has had to fire employees](https://www.vice.com/en_us/article/bjp9zv/facebook-employees-look-at-user-data) who abused their privilege to access user data. Uber also [got in trouble](https://www.theverge.com/2016/1/6/10726004/uber-god-mode-settlement-fine) over a “God View” that allowed employees to track customers without permission and had to change their treatment of personal data as a result.

### Don’t retain data

Along the same line of thinking as not collecting PII in the first place, you should also avoid retaining PII beyond how long you actually need it. If it no longer provides value, then it can actually be a net negative to keep it because you maintain the risk of its being stolen. You can reduce your exposure by regularly pruning data.

A recent trend is to offload storing sensitive information to other companies. For example, [Stripe](https://stripe.com/) provides a way to collect credit and debit card numbers without the numbers ever touching your system. This makes it much easier to [achieve PCI compliance](https://stripe.com/guides/pci-compliance#how-stripe-helps-organizations-achieve-and-maintain-pci-compliance).

Another more general example is [Very Good Security](https://www.verygoodsecurity.com/). They promote a [zero-data approach](https://blog.verygoodsecurity.com/posts/announcing-very-good-security's-zero-data-mission/) in which they collect and store any sensitive information you want, you get harmless tokens to store in your system, and then you use the tokens later when you actually need the data. This effectively allows you to offload the job of securing that data to someone else.

This is the “you can’t lose what you don’t have” philosophy.

## Conclusion

Protecting PII is a never-ending challenge. Remember that it only takes a single vulnerability for your service to leak all the PII it has ever collected. Even if your security posture is strong at the moment, it takes constant vigilance to keep your users safe.

It’s important to be aware of the methods that can cause websites to lose PII, but it’s just as important to regularly review whether or not you are actually protected from these methods. By doing so, you make your website worthy of the trust your users have given you.

* * *
## Do you work on an app with PII? Protect PII while using powerful analytics. 

[LogRocket](https://logrocket.com/signup/) is a frontend application monitoring solution that pairs performance monitoring, automatic bug reproduction, and user replay to help you understand how issues affect your users. 

LogRocket leaves a variety of options to ensure PII never leaves your app and you stay compliant. These include an on-premises deployment, automatic sanitization, and the ability to immediately delete user data. Learn more about these privacy controls [here.](https://docs.logrocket.com/docs/privacy) 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ugtxqsfawuf9rjqhgwyd.png)

LogRocket works perfectly with any app, regardless of framework, and has plugins to log additional context from Redux, Vuex, and @ngrx/store. 

LogRocket records console logs, page load times, stacktraces, slow network requests/responses with headers + bodies, browser metadata, and custom logs. 

[Try it for free.](https://logrocket.com/signup/) 
* * * 

The post [How to handle PII in websites and web apps](https://blog.logrocket.com/how-to-handle-pii-websites-web-apps/) appeared first on [LogRocket Blog](https://blog.logrocket.com).