Skip to content

Commit

Permalink
fix: fixed IDN check on urls
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Feb 19, 2021
1 parent d882196 commit a72745c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 10 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1278,14 +1278,16 @@ class SpamScanner {
}
}

for (const link of links) {
const urlHostname = this.getHostname(link);
if (urlHostname) {
const toASCII = punycode.toASCII(urlHostname);
if (toASCII.startsWith('xn--'))
messages.push(
`Possible IDN homograph attack from link of "${link}" with punycode converted hostname of "${toASCII}".`
);
if (this.config.checkIDNHomographAttack) {
for (const link of links) {
const urlHostname = this.getHostname(link);
if (urlHostname) {
const toASCII = punycode.toASCII(urlHostname);
if (toASCII.startsWith('xn--'))
messages.push(
`Possible IDN homograph attack from link of "${link}" with punycode converted hostname of "${toASCII}".`
);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ test('should detect not phishing with different org domains (temporary)', async
});

test('should detect idn masquerading', async (t) => {
const client = new Redis();
const scanner = new SpamScanner({ client, checkIDNHomographAttack: true });
const scan = await scanner.scan(fixtures('idn.eml'));
t.true(scan.is_spam);
t.true(scan.results.phishing.length > 0);
Expand Down

0 comments on commit a72745c

Please sign in to comment.