Improper Validation of Certificate with Host Mismatch

ID

scala.smtp.scala_smtp_rule_insecuresmtp

Severity

high

Remediation Complexity

medium

Remediation Risk

medium

Remediation Effort

medium

Resource

Smtp

Language

Scala

Description

Server identity verification is disabled when making SSL connections.

Rationale

Server identity verification is disabled when making SSL connections.

The following code illustrates a vulnerable pattern detected by this rule:

object ReceiptMailer {
  @throws[Exception]
  def send(): Unit = {
    // VULNERABLE: Improper Validation of Certificate with Host Mismatch
    val plain = new SimpleEmail
    plain.setHostName("smtp.internal")
    plain.setSSLOnConnect(false)

    // VULNERABLE: Improper Validation of Certificate with Host Mismatch
    val plainOverTls = new SimpleEmail
    plainOverTls.setHostName("smtp2.internal")
    plainOverTls.setSSLOnConnect(true)

    // VULNERABLE: Improper Validation of Certificate with Host Mismatch
    val withAttachment = new MultiPartEmail
    withAttachment.setHostName("smtp3.internal")
    withAttachment.setSSLOnConnect(true)

    // VULNERABLE: Improper Validation of Certificate with Host Mismatch
    val html = new HtmlEmail
    html.setHostName("smtp4.internal")
    html.setSSLOnConnect(true)

    // VULNERABLE: Improper Validation of Certificate with Host Mismatch
    val withImages = new ImageHtmlEmail
    withImages.setHostName("smtp5.internal")
    withImages.setSSLOnConnect(true)
    withImages.setSSLCheckServerIdentity(true)

    // The identity check set before the connect flag is the control for call order.
    // VULNERABLE: Improper Validation of Certificate with Host Mismatch
    val checkedFirst = new ImageHtmlEmail
    checkedFirst.setHostName("smtp6.internal")
    checkedFirst.setSSLCheckServerIdentity(true)
    checkedFirst.setSSLOnConnect(true)

    // VULNERABLE: Improper Validation of Certificate with Host Mismatch
    val unchecked = new ImageHtmlEmail
    unchecked.setHostName("smtp7.internal")
    unchecked.setSSLOnConnect(true)
  }
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

References

© 2026 Xygeni. All rights reserved