T09 · Insecure Skill Coding Practices
- Location
email_sender.py:178- Finding
SMTP Credentials May Be Transmitted Without Encryption
- Content
View full analysis
Vulnerability Details
File Location:
email_sender.py, lines 178–185
Vulnerability Type: Plaintext transmission of SMTP credentials and email content
Risk Level: HighVulnerable Code:
python if config.get('useTLS', False): server = smtplib.SMTP_SSL(config['server'], config['port']) else: server = smtplib.SMTP(config['server'], config['port']) if config.get('startTLS', False): server.starttls() server.login(config['username'], config['password'])Technical Analysis
Both
useTLSandstartTLSdefault toFalse. If either setting is omitted from the configuration, or both are explicitly disabled, the application creates a plaintext SMTP connection and subsequently invokesserver.login().SMTP authentication mechanisms commonly encode credentials rather than encrypting them. Without transport-layer encryption, a network-positioned attacker can observe the authentication exchange, SMTP envelope, message headers, email body, and attachments. The application does not reject insecure configurations or require encryption before authentication.
The SMTP hostname and port are also configuration-controlled. Anyone able to provide or modify the configuration can direct the application to an attacker-operated SMTP endpoint. This does not expose unrelated system privileges, but it can disclose the configured mailbox credentials and all email data sent during the affected execution.
Attack Path
- The attacker modifies the SMTP configuration, supplies a configuration through
--config, or causes TLS-related properties to be omitted. - The resulting configuration has both
useTLSandstartTLSabsent or set tofalse. - The application opens a plaintext connection with
smtplib.SMTP(config['server'], config['port']). - The application calls
server.login(config['username'], config['password'])without first establishing TLS. - An attacker controlling the S ...[truncated 865 chars]
- The attacker modifies the SMTP configuration, supplies a configuration through
- Remediation
View remediation
Remediation Suggestions
-
Require encrypted SMTP transport before authentication. Reject configurations where neither implicit TLS nor STARTTLS is enabled.
-
Use TLS as the secure default instead of defaulting both controls to
False. -
Create and pass a certificate-validating SSL context:
python import ssl context = ssl.create_default_context() if config.get("useTLS", True): server = smtplib.SMTP_SSL( config["server"], config["port"], context=context ) elif config.get("startTLS", False): server = smtplib.SMTP(config["server"], config["port"]) server.ehlo() server.starttls(context=context) server.ehlo() else: raise ValueError("Refusing to authenticate over plaintext SMTP") server.login(config["username"], config["password"]) -
Do not disable certificate or hostname validation.
-
Validate configuration before connecting, including the server hostname, port, and TLS mode.
-
If plaintext SMTP is essential for isolated development environments, place it behind an explicit option such as
allowInsecureSMTP, default it tofalse, and display a prominent warning. -
Prefer app-specific credentials with the minimum permissions necessary and rotate any credentials that may have traversed an unencrypted connection.
-
Add automated tests confirming that authentication cannot occur unless a validated TLS session has been established.
-
