URL / IP / Email defanging with Javascript
Coded with 💙 by edoardottt
Defanging is the process where URLs, IPs, and email addresses no longer become effective (or clickable if you want). Why? Links can be used for phishing or it's simply safer to display them in a weakened way if they are malicious resources (eg. Indicators of compromise for a malware).
npm install defangjs@latest
var defangjs = require('defangjs');
var url = 'https://edoardottt.com/index.html';
console.log(defangjs.Url(url));
// hxxps[://]edoardottt[.]com/index.html
var maliciousIpv4 = '666.666.666.666';
console.log(defangjs.Ip(maliciousIpv4));
// 666[.]666[.]666[.]666
var maliciousIpv6 = '2001:0db8:85a3:0000:0000:8a2e:0370:7334';
console.log(defangjs.Ip(maliciousIpv6));
// 2001[:]0db8[:]85a3[:]0000[:]0000[:]8a2e[:]0370[:]7334
var maliciousEmail = 'mailto:[email protected]';
console.log(defangjs.Email(maliciousEmail));
// mailto[:]edoardott@gmail[.]com
npm test
Take a look to test.js, this file contains all the supported formats (URLs, various protocols, ports, Ipv4 and Ipv6 and email addresses)
Detailed changes for each release are documented in the release notes.
If you want to contribute to this project, you can start opening an issue.
This repository is under GNU General Public License v3.0.
edoardottt.com to contact me.