{"id":13877892,"url":"https://github.com/ankane/ip_anonymizer","last_synced_at":"2025-11-17T14:06:45.303Z","repository":{"id":56877935,"uuid":"132297516","full_name":"ankane/ip_anonymizer","owner":"ankane","description":"IP address anonymizer for Ruby and Rails","archived":false,"fork":false,"pushed_at":"2024-12-30T01:30:12.000Z","size":29,"stargazers_count":105,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-11-01T07:09:32.169Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ankane.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-06T01:34:40.000Z","updated_at":"2025-10-28T02:26:35.000Z","dependencies_parsed_at":"2024-06-24T20:35:02.971Z","dependency_job_id":"6c682f61-52aa-4abc-b862-a7cbe389a095","html_url":"https://github.com/ankane/ip_anonymizer","commit_stats":{"total_commits":37,"total_committers":3,"mean_commits":"12.333333333333334","dds":0.4054054054054054,"last_synced_commit":"75cca406598700288bfdb4ee7aa4bfc7c39ac2b2"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ankane/ip_anonymizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fip_anonymizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fip_anonymizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fip_anonymizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fip_anonymizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankane","download_url":"https://codeload.github.com/ankane/ip_anonymizer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fip_anonymizer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":282521097,"owners_count":26683141,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-03T02:00:05.676Z","response_time":108,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T08:01:34.203Z","updated_at":"2025-11-17T14:06:45.286Z","avatar_url":"https://github.com/ankane.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# IP Anonymizer\n\n:earth_americas: IP address anonymizer for Ruby and Rails\n\nWorks with IPv4 and IPv6\n\nDesigned to help with [GDPR](https://en.wikipedia.org/wiki/General_Data_Protection_Regulation) compliance\n\n[![Build Status](https://github.com/ankane/ip_anonymizer/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/ip_anonymizer/actions)\n\n## Getting Started\n\nAdd these lines to your application’s Gemfile:\n\n```ruby\ngem \"ip_anonymizer\"\n```\n\nThere are two strategies for anonymizing IPs.\n\n### Masking\n\nThis is the approach [Google Analytics uses for IP anonymization](https://support.google.com/analytics/answer/2763052):\n\n- For IPv4, set the last octet to 0\n- For IPv6, set the last 80 bits to zeros\n\n```ruby\nIpAnonymizer.mask_ip(\"8.8.4.4\")\n# =\u003e \"8.8.4.0\"\n\nIpAnonymizer.mask_ip(\"2001:4860:4860:0:0:0:0:8844\")\n# =\u003e \"2001:4860:4860::\"\n```\n\nAn 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`).\n\n### Hashing\n\nTransform IP addresses with a keyed hash function (PBKDF2-HMAC-SHA256).\n\n```ruby\nIpAnonymizer.hash_ip(\"8.8.4.4\", key: \"secret\")\n# =\u003e \"6.128.151.207\"\n\nIpAnonymizer.hash_ip(\"2001:4860:4860:0:0:0:0:8844\", key: \"secret\")\n# =\u003e \"f6e4:a4fe:32dc:2f39:3e47:84cc:e85e:865c\"\n```\n\nAn advantage of this approach is different IPs will have different hashes (with the exception of collisions).\n\nMake sure the key is kept secret and at least 30 random characters. Otherwise, a rainbow table can be constructed. You can generate a good key with:\n\n```ruby\nSecureRandom.hex(32)\n```\n\n## Rails\n\nAutomatically anonymize `request.remote_ip` in Rails.\n\nFor masking, add to `config/application.rb`:\n\n```ruby\nconfig.middleware.insert_after ActionDispatch::RemoteIp, IpAnonymizer::MaskIp\n```\n\nFor hashing, use:\n\n```ruby\nconfig.middleware.insert_after ActionDispatch::RemoteIp, IpAnonymizer::HashIp, key: \"secret\"\n```\n\n## Related Projects\n\n- [Logstop](https://github.com/ankane/logstop) - Keep personally identifiable information (PII) out of your logs\n\n## History\n\nView the [changelog](https://github.com/ankane/ip_anonymizer/blob/master/CHANGELOG.md)\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https://github.com/ankane/ip_anonymizer/issues)\n- Fix bugs and [submit pull requests](https://github.com/ankane/ip_anonymizer/pulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n\nTo get started with development:\n\n```sh\ngit clone https://github.com/ankane/ip_anonymizer.git\ncd ip_anonymizer\nbundle install\nbundle exec rake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fip_anonymizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankane%2Fip_anonymizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fip_anonymizer/lists"}