Skip to content

Commit b78d047

Browse files
committed
Add email domain NFC normalization
IDNA, which we use for other minfraud libraries, requires NFC normalization before punycoding. This adds said NFC normalization to the email domain.
1 parent 8c74e0d commit b78d047

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ CHANGELOG
2727
become `gmail.com`.
2828
* Additional `gmail.com` typos are now normalized when `hashAddress` is
2929
used. For example, `gmali.com` will become `gmail.com`.
30+
* When `hashAddress` is used, the domain part of an email address is now
31+
normalized to NFC.
3032

3133
6.0.0 (2023-12-05)
3234
------------------

src/request/email.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ describe('Email()', () => {
216216
md5: md5('[email protected]'),
217217
domain: 'example.comcom',
218218
},
219+
{
220+
email: 'example@bu\u0308cher.com',
221+
md5: '2b21bc76dab3c8b1622837c1d698936c',
222+
domain: 'bu\u0308cher.com',
223+
},
224+
{
225+
email: 'example@b\u00FCcher.com',
226+
md5: '2b21bc76dab3c8b1622837c1d698936c',
227+
domain: 'b\u00FCcher.com',
228+
},
219229
];
220230

221231
test.each(normalizeTests)('%p', (arg) => {

src/request/email.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ export default class Email implements EmailProps {
363363
// We don't need to strip a trailing '.' because validation (isEmail())
364364
// rejects domains that have it.
365365

366-
domain = punycode.toASCII(domain);
366+
domain = punycode.toASCII(domain.normalize('NFC'));
367367

368368
domain = domain.replace(/(?:\.com){2,}$/, '.com');
369369
domain = domain.replace(/^\d+(?:gmail?\.com)$/, 'gmail.com');

0 commit comments

Comments
 (0)