News for hackers. Stuff that matters.
Re:Tell HN: After 10 years of experiments, custom username e... by mutt2016 on Monday August 15, 2022 @09:50PM (#32478336)
Frameworks usually have some sort of email parser. Email parsing is non trivial. But I agree matching .*[email protected]$ would probably work fine.
Re:Tell HN: After 10 years of experiments, custom username e... by simondotau on Tuesday August 16, 2022 @06:07PM (#32489588)
Definitely use a real email address parser if it’s available, easy and/or you’re dealing with unknown email addresses. But absent any strange circumstances there’s also nothing wrong with basic string manipulation if it’s done properly (e.g. split on @ and test for an exact string match, case insensitive). As personal preference, I’d choose that over regexp.
Re:Tell HN: After 10 years of experiments, custom username e... by drewgross on Wednesday August 17, 2022 @01:26PM (#32499239)
Hackers deliberately create strange circumstances, it's the primary way to find exploits. Any code that relies on a lack of strange circumstances is a time-bomb.
Re:Tell HN: After 10 years of experiments, custom username e... by simondotau on Thursday August 18, 2022 @12:00AM (#32505099)
There aren't too many strange circumstances for a properly written split/test routine. Described more precisely:—

  1. Split on @
  2. Get last string from array
  3. Convert to lowercase
  4. Perform exact string compare against target domain
It's possible that there's some window for obscure unicode hijinks, but I'd posit that a regexp parser or a "proper" email parsing library is just as at-risk. Possibly more so as those would be significantly more complicated and involve significantly more code.
Re:Tell HN: After 10 years of experiments, custom username e... by blodorn on Monday August 15, 2022 @11:45PM (#32478982)
What is the purpose of the ? here?
Re:Tell HN: After 10 years of experiments, custom username e... by wiml on Tuesday August 16, 2022 @12:59AM (#32479359)
It makes the preceding * less "greedy". I don't think it has any effect on the set of strings matched by this regexp, though, which is a simple string suffix check.
Re:Tell HN: After 10 years of experiments, custom username e... by jakopo87 on Tuesday August 16, 2022 @03:21AM (#32480112)
I agree, but the dot should be escaped because it matches any character, so "@domain\.com$" should just works for.
Re:Tell HN: After 10 years of experiments, custom username e... by jasonm23 on Tuesday August 16, 2022 @06:14AM (#32481058)
Or use [.] so it's super clear on the a-human-is-reading-it parse.
Re:Tell HN: After 10 years of experiments, custom username e... by account42 on Wednesday August 17, 2022 @09:42AM (#32496247)
I don't think that's clearer because for [.] I need to remember that . does not need to be escaped in character classes whereas \. is quite clearly an escaped literal character without any advanced regexp knowledge.
Re:Tell HN: After 10 years of experiments, custom username e... by nfhshy68 on Monday August 15, 2022 @11:55PM (#32479031)
I dunno, but I've seen a bug like this in prod while consulting.
Re:Tell HN: After 10 years of experiments, custom username e... by jasonm23 on Tuesday August 16, 2022 @06:13AM (#32481041)
Non-greedy match (match what's necessary nothing more.)

The default is greedy... match match match nom nom nom!