Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
ip-anonymize
Advanced tools
Truncate IPv4 and IPv6 address binary and format back as an IP address.
x:x:x:x:x:x:x:x
formatx:x:x:x:x:x:d.d.d.d
formatanonymize('192.168.42.1') // -> '192.168.42.0'
anonymize('192.168.42.1', 16) // -> '192.168.0.0'
anonymize('::ffff:192.168.42.1', 16) // -> '::ffff:192.168.0.0'
anonymize('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', 16, 16) // -> 'ffff::'
This package converts an IP address to binary and keeps a specified number of bits on the left while setting the remaining bits to zero. It then converts the binary back into an IP address string and returns it. For example, if the binary was 10101010
and we wanted to keep the first four bits (4-bit mask), the binary would become 10100000
.
Note: Although this technique adds some uncertainty about the actual IP address, using this package is not sufficient to anonymize users in all cases, such as if the traffic from one user comes from one large IP block or if other information is stored along with the truncated IP address. This package is meant to simply help with truncating and formatting IP addresses and makes no claim that this technique is the best choice for any particular use case. Take extra care when storing IP addresses along with other potentially identifying information.
$ npm install ip-anonymize --save # Using npm
$ yarn add ip-anonymize # OR use yarn
const anonymize = require('ip-anonymize')
const ipv4 = '192.168.1.16'
anonymize(ipv4) // '192.168.1.0'
// Use 16-bit mask
anonymize(ipv4, 8) // '192.0.0.0'
const ipv6 = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'
anonymize(ipv6) // 'ffff:ff00::'
// Use 16-bit mask (first number is for IPv4, second for IPv6)
anonymize(ipv6, 16, 16) // 'ffff::'
// IPv4-compatible IPv6 and IPv4-mapped IPv6 use the IPv4 mask on the IPv4 part
const ipv4Compatible = '::192.168.0.1'
anonymize(ipv4Compatible, 16, 16) // '::192.168.0.0'
const ipv4Mapped = '::ffff:192.168.0.1'
anonymize(ipv4Mapped, 16, 16) // '::ffff:192.168.0.0'
// Returns null if IP address is invalid
anonymize('not an ip', 16, 16) // null
const anonymize = require('ip-anonymize')
anonymize(ip [, v4MaskLength, v6MaskLength])
ip
: String
, The IP address to anonymizev4MaskLength
: Number
, Number of bits to keep at the beginning of an IPv4 address or IPv4 part of IPv4-compatible/mapped IPv6 address (default: 24
)v6MaskLength
: Number
, Number of bits to keep at the beginning of an IPv6 address (default: 24
)Returns null
if the IP address is invalid.
FAQs
Anonymize IP addresses, works with IPv4 and IPv6
The npm package ip-anonymize receives a total of 8,943 weekly downloads. As such, ip-anonymize popularity was classified as popular.
We found that ip-anonymize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.