Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly create an SSL context when emailing #574

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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