README.md in ip_anonymizer-0.1.0 vs README.md in ip_anonymizer-0.1.1

- old
+ new

@@ -1,11 +1,15 @@ # IP Anonymizer -:earth_americas: IP address anonymizer for Ruby +:earth_americas: IP address anonymizer for Ruby and Rails -Works with IPv4 and IPv6, and includes middleware for Rails +Works with IPv4 and IPv6 +Designed to help with [GDPR](https://en.wikipedia.org/wiki/General_Data_Protection_Regulation) compliance + +[![Build Status](https://travis-ci.org/ankane/ip_anonymizer.svg?branch=master)](https://travis-ci.org/ankane/ip_anonymizer) + ## Getting Started Add these lines to your application’s Gemfile: ```ruby @@ -16,22 +20,22 @@ ### Masking This is the approach [Google Analytics uses for IP anonymization](https://support.google.com/analytics/answer/2763052): -- For IPv4, the last octet is set to 0 -- For IPv6, the last 80 bits are set to zeros +- For IPv4, set the last octet to 0 +- For IPv6, set the last 80 bits to zeros ```ruby IpAnonymizer.mask_ip("8.8.4.4") # => "8.8.4.0" IpAnonymizer.mask_ip("2001:4860:4860:0:0:0:0:8844") # => "2001:4860:4860::" ``` -An advantange of this approach is geocoding will still work, only with slightly less accuracy. +An advantange of this approach is geocoding will still work, only with slightly less accuracy. A potential disadvantage is different IPs will have the same mask (`8.8.4.4` and `8.8.4.5` both become `8.8.4.0`). ### Hashing Transform IP addresses with a keyed hash function (PBKDF2-HMAC-SHA256). @@ -41,12 +45,18 @@ IpAnonymizer.hash_ip("2001:4860:4860:0:0:0:0:8844", key: "secret") # => "f6e4:a4fe:32dc:2f39:3e47:84cc:e85e:865c" ``` -Be sure to keep the key secret, or else a rainbow table can be constructed. +An advantage of this approach is different IPs will have different hashes. +Make sure the key is kept secret and at least 30 random characters. Otherwise, a rainbow table can be constructed. In Rails, you can generate a good key with: + +```sh +rails secret +``` + ## Rails Automatically anonymize `request.remote_ip` in Rails. For masking, add to `config/application.rb`: @@ -58,9 +68,13 @@ For hashing, use: ```ruby config.middleware.insert_after ActionDispatch::RemoteIp, IpAnonymizer::HashIp, key: "secret" ``` + +## Related Projects + +- [Logstop](https://github.com/ankane/logstop) - Keep personally identifiable information (PII) out of your logs ## History View the [changelog](https://github.com/ankane/ip_anonymizer/blob/master/CHANGELOG.md)