T09 · Insecure Skill Coding Practices
- Location
email_sender.py:19- Finding
SMTP Authentication and Email Transmission May Occur Without Transport Encryption
- Content
View full analysis
Vulnerability Details
File Location:
email_sender.py, lines 19–20
Vulnerability Type: Conditional plaintext transmission of SMTP credentials and email contents
Risk Level: HighComplete Code Snippet:
python server = smtplib.SMTP_SSL(config['server'], config['port']) if config.get('useTLS') else smtplib.SMTP(config['server'], config['port']) server.login(config['username'], config['password'])Technical Analysis
The SMTP connection is encrypted only when the
useTLSconfiguration value evaluates to true. If that setting is false, missing, or otherwise falsey, the code creates a plaintextsmtplib.SMTPconnection and immediately callsserver.login()without first negotiating STARTTLS.As a result, SMTP authentication credentials and subsequently transmitted message data may be exposed over the network. Although some authentication mechanisms encode credentials, encoding does not provide confidentiality. The implementation also does not create an explicit verified TLS context or reject configurations that disable transport encryption.
Attack Path
- The SMTP configuration omits
useTLSor sets it tofalse. - The skill opens a plaintext SMTP connection using
smtplib.SMTP. - It authenticates through
server.login()without callingstarttls(). - An attacker with a network position between the host and SMTP server captures or manipulates the SMTP traffic.
- The attacker may recover SMTP credentials and observe email bodies or attachments.
- Stolen credentials may then be used against the SMTP service within the permissions assigned to that account.
Impact Assessment
A successful network interception may disclose the configured SMTP username and password, email recipients, subjects, message contents, and attachments. Depending on the SMTP account's permissions, stolen credentials could permit unauthorized email transmission, impersonation of the configured sender, sp ...[truncated 268 chars]
- The SMTP configuration omits
- Remediation
View remediation
Remediation Suggestions
- Require encrypted SMTP transport rather than silently falling back to plaintext.
- For implicit TLS, use
smtplib.SMTP_SSLwithssl.create_default_context(). - For explicit TLS, connect with
smtplib.SMTP, issueEHLO, callstarttls(context=ssl.create_default_context()), issueEHLOagain, and only then calllogin(). - Reject missing or false TLS settings by default. If plaintext SMTP must be supported for an exceptional local environment, require an explicit insecure opt-in and display a prominent warning.
- Validate the SMTP hostname and rely on certificate verification provided by a secure default SSL context.
- Use a context manager or
try/finallyblock to ensure the SMTP connection is closed safely on authentication, attachment-processing, or transmission failures. - Protect the configuration file with restrictive permissions and use a dedicated, least-privileged SMTP credential that is not reused by other services.
