T09 · Insecure Skill Coding Practices
- Location
email_sender.py:137- Finding
SMTP Credentials and Message Content Can Be Transmitted Without Encryption
- Content
View full analysis
Vulnerability Details
File Location:
email_sender.py, lines 137-155
Vulnerability Type: Optional plaintext SMTP authentication and transmission
Risk Level: HighVulnerable Code
python # Connect to SMTP server context = ssl.create_default_context() if self.config.get('use_ssl', False): # SSL connection server = smtplib.SMTP_SSL( self.config['smtp_server'], self.config['smtp_port'], context=context ) else: # TLS connection (default) server = smtplib.SMTP( self.config['smtp_server'], self.config['smtp_port'] ) if self.config.get('use_tls', True): server.starttls(context=context) # Login and send server.login(self.config['username'], self.config['password']) server.send_message(msg, from_addr=self.config['username'], to_addrs=all_recipients)Technical Analysis
The application permits both
use_sslanduse_tlsto be disabled. When this occurs, it creates a plaintext SMTP connection and proceeds to callserver.login()without first establishing an encrypted transport.Depending on the authentication mechanisms supported by the SMTP server, the username and password may be transmitted in a trivially decodable form. Message headers, recipient addresses, body content, and attachments are also exposed to interception or modification.
Although TLS is enabled by default, secure transport is not enforced. An unsafe configuration, such as
EMAIL_USE_TLS=falsewithEMAIL_USE_SSL=false, is sufficient to activate the vulnerable path. The code does not reject this configuration or verify that encryption is active before authenticating.Attack Path
- The Skill is deployed with
use_sslanduse_tlsdisabled, whether through an explicit environment setting, an integration error, or an unsafe custom SMTP configuration. - The Skill creates a standard plaintext
smtplib.SMTPconnection.
...[truncated 1149 chars]
- The Skill is deployed with
- Remediation
View remediation
Remediation Suggestions
- Reject configurations in which both
use_sslanduse_tlsare disabled. - Make encrypted transport mandatory before calling
login()or transmitting a message. - Prefer implicit TLS through
SMTP_SSLon an appropriate port or mandatory STARTTLS with a default certificate-verifying SSL context. - After calling
starttls(), issueehlo()again and ensure the operation completed successfully before authentication. - Fail closed if the SMTP server does not advertise STARTTLS or if certificate validation fails.
- Consider replacing the two booleans with a single validated transport mode, such as
implicit_tlsorstarttls, to prevent contradictory settings. - Add tests confirming that plaintext authentication is impossible under every configuration combination.
- Document that disabling certificate verification or encrypted transport is unsupported.
Example validation:
python use_ssl = self.config.get('use_ssl', False) use_tls = self.config.get('use_tls', True) if not use_ssl and not use_tls: raise ValueError("Encrypted SMTP transport is required")- Reject configurations in which both
