Back to cheatsheets
Privacy
Phishing URL Detection
Detect spoofing, suspicious TLDs, punycode homograph attacks, and redirect chains.
What you'll learn
- Punycode / homograph detection
- Suspicious TLD and pattern check
How to use these snippets
- Click the Copy button next to any snippet to copy it to your clipboard.
- Paste the code into your project, IDE, or terminal.
- Replace placeholder values (like
example.comoryour-secret) with your actual data. - Review the code comments for important security notes and caveats.
- Try the interactive related tool to see the concept in action.
Code Snippets
Copy-paste code snippets
2 ready-to-use snippets for phishing url detection. Click copy and paste into your project.
Punycode / homograph detection
function detectHomograph(url) {
try {
const u = new URL(url);
const domain = u.hostname;
// Check for punycode (IDN)
if (domain.includes('xn--')) {
// Decode and compare
const decoded = domain; // use punycode library
return {
suspicious: true,
reason: 'IDN/punycode domain — possible homograph attack',
original: domain,
};
}
// Check for lookalike characters
const lookalikes = /[0O1lI|]/;
if (lookalikes.test(domain)) {
return {
suspicious: true,
reason: 'Contains lookalike characters (0/O, 1/l, I/|)',
};
}
return { suspicious: false };
} catch (e) {
return { suspicious: true, reason: 'Invalid URL' };
}
}
Suspicious TLD and pattern check
const SUSPICIOUS_TLDS = [
'.zip', '.mov', '.xyz', '.top', '.tk', '.ml',
'.ga', '.cf', '.gq', '.cn', '.ru'
];
function checkUrl(url) {
const flags = [];
const u = new URL(url);
// Suspicious TLD
if (SUSPICIOUS_TLDS.some(tld => u.hostname.endsWith(tld)))
flags.push('Suspicious TLD');
// Excessive subdomains
if (u.hostname.split('.').length > 5)
flags.push('Excessive subdomain depth');
// IP address as hostname
if (/^\d+\.\d+\.\d+\.\d+$/.test(u.hostname))
flags.push('Raw IP address as hostname');
// @ symbol in URL (user:pass@host)
if (u.href.includes('@') && !u.href.includes('@'))
flags.push('Credentials in URL');
// URL shortener
const shorteners = ['bit.ly', 'tinyurl.com', 't.co', 'goo.gl'];
if (shorteners.some(s => u.hostname === s))
flags.push('URL shortener — destination unknown');
return flags;
}
Tool
Related ShieldX tool
Try this concept hands-on with the interactive tool.
100% Free · No signup · No cost
Generate something unguessable right now
148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.
Part of the Toolly ecosystem · secure.toolly.site