Make sure the regex used in this method call cannot lead to denial of service

Viewed 69

In the below code SonarQube suggest to avoid catastrophic backtracking Please suggest how to resolve this denial of service by SonarQube

public static boolean ValidEmailAddress(String email)
{
    final String ePattern = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
            + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
    java.util.regex.Pattern pattern = Pattern.compile(ePattern);
    java.util.regex.Matcher m = pattern.matcher(email);
    return m.matches();
}
0 Answers
Related