Skip to content

Commit

Permalink
Explicitly create an SSL context when emailing (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson authored Jul 31, 2023
1 parent b59186d commit 1cd7483
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/574.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long-standing issue where Sydent would not verify the configured SMTP server's certificates. See [GHSA-p6hw-wm59-3q5q](https://github.com/matrix-org/sydent/security/advisories/GHSA-p6hw-wm59-3g5g) and [CVE-2023-38686](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-38686). Reported by Martin Schobert, [Pentagrid AG](https://pentagrid.ch).
8 changes: 6 additions & 2 deletions sydent/util/emailutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import random
import smtplib
import ssl
import string
import urllib
from html import escape
Expand Down Expand Up @@ -106,11 +107,14 @@ def sendEmail(
)
try:
smtp: smtplib.SMTP
# Explicitly create a context, to ensure we verify the server's certificate
# and hostname.
ctx = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH)
if mailTLSMode == "SSL" or mailTLSMode == "TLS":
smtp = smtplib.SMTP_SSL(mailServer, mailPort, myHostname)
smtp = smtplib.SMTP_SSL(mailServer, mailPort, myHostname, context=ctx)
elif mailTLSMode == "STARTTLS":
smtp = smtplib.SMTP(mailServer, mailPort, myHostname)
smtp.starttls()
smtp.starttls(context=ctx)
else:
smtp = smtplib.SMTP(mailServer, mailPort, myHostname)
if mailUsername != "":
Expand Down

0 comments on commit 1cd7483

Please sign in to comment.