T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/send-email.py:18
- Finding
- Hardcoded SMTP Credentials Exposed in Source Code<![CDATA[ ## Vulnerability Details **File Location**: `scripts/send-email.py:18-22` **Vulnerability Type**: Hardcoded authentication credentials **Risk Level**: Critical ### Vulnerable Code ```python # 配置 SMTP_HOST = "smtp.163.com" SMTP_PORT = 465 SMTP_USER = "m13430467261@163.com" SMTP_PASS = "FC27pgp77tc5Vvhv" SMTP_FROM = "Judy <m13430467261@163.com>" ``` The exposed values are subsequently used to authenticate: ```python with smtplib.SMTP_SSL(SMTP_HOST, SMTP_PORT, context=context) as server: server.login(SMTP_USER, SMTP_PASS) server.sendmail(SMTP_FROM, to_email, msg.as_string()) ``` ### Technical Analysis The sender contains a plaintext, live-looking SMTP username and password. Any person who can access the package or its source can recover these values without executing the Skill. This contradicts the documentation, which directs users to supply SMTP credentials through an environment configuration file. Embedding credentials in distributed source code prevents safe per-deployment secret management and causes the same account to be shared across all copies of the package. Removing the credential from the current file alone is insufficient if it has already been committed or published, because it may remain available through package archives or repository history. ### Attack Path 1. An attacker downloads or otherwise obtains the Skill package. 2. The attacker opens `scripts/send-email.py` and extracts `SMTP_USER` and `SMTP_PASS`. 3. The attacker attempts authentication against `smtp.163.com` on port 465. 4. If the credential remains valid, the attacker uses the mailbox to send unsolicited, fraudulent, or phishing messages. 5. Messages may appear to originate from the embedded account, damaging its reputation and potentially causing service suspension or blocklisting. ### Impact Assessment Successful exploitation may provide authenticated access to the configured SMTP account. The attacker could send messages as the exposed identity, consu ...[truncated 343 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Revoke and rotate the exposed SMTP password immediately. 2. Remove the credential from the source file and repository history. 3. Load secrets from environment variables or an approved secret manager: ```python import os SMTP_HOST = os.environ["SMTP_HOST"] SMTP_PORT = int(os.environ.get("SMTP_PORT", "465")) SMTP_USER = os.environ["SMTP_USER"] SMTP_PASS = os.environ["SMTP_PASS"] SMTP_FROM = os.environ["SMTP_FROM"] ``` 4. Fail closed with a clear configuration error if any required value is absent. 5. Ensure secret files are excluded from version control and stored with restrictive filesystem permissions. 6. Use separate, least-privileged SMTP credentials for each deployment. 7. Add automated secret scanning to pre-commit and CI workflows. ]]>
