Skip to content

Email addresses validated despite cleared validation criteria #167

Closed

Description

https://github.com/bbottema/simple-java-mail/blob/master/src/main/java/org/simplejavamail/mailer/Mailer.java#L275

The validate method tightly couples validation for injection attacks alongside email addresses validation. These are different types of validation. Consider:

public boolean validate(final Email email) {
  validateSenders(email);
  validateRecipients(email);
  validateAttacks(email);
}

This would allow for global settings to control validation. For example:

public boolean validate(final Email email) {
  if( validate() ) {
    validateSenders(email);
    validateRecipients(email);
    validateAttacks(email);
  }
}

public boolean validateSenders(final Email email) {
  if( validateSenders() ) {
    final InternetAddress[] addresses = email.getAddresses(FROM);
    if (!EmailAddressValidator.isValid(addresses, getEmailAddressCriteria())) {
      // ...
  }
}

Activity

  1. bbottema commented on Sep 20, 2018

    @bbottema
    Owner

    What's the use case for global control settings? Why not always check everything?

  2. bbottema commented on Sep 22, 2018

    @bbottema
    Owner

    This is already possible:

    currentMailerBuilder
       .clearEmailAddressCriteria()
       (..)

    This tells Simple Java Mail that there is no email address criteria to check and so will omit email address validation completely, yet keep the injection tests.

    Does this solve your problem?

  3. bbottema commented on Sep 26, 2018

    @bbottema
    Owner

    @davejarvis, had any luck with this yet?

  4. self-assigned this
    on Oct 3, 2018
  5. added this to the 5.0.6 milestone on Oct 3, 2018
  6. changed the title [-]Separate validation concerns[/-] [+]Email addresses validated despite cleared validation validation criteria[/+] on Oct 3, 2018
  7. added a commit that references this issue on Oct 3, 2018
  8. bbottema commented on Oct 3, 2018

    @bbottema
    Owner

    Your analyses is spot on. Moreover emailAddressCriteria is garuanteed to be non-null, so the null-check is not only wrong, it is completely superfluous.

    Released fix in 5.0.6, please confirm.

  9. ghost changed the title [-]Email addresses validated despite cleared validation validation criteria[/-] [+]Email addresses validated despite cleared validation criteria[/+] on Nov 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions