T09 · Insecure Skill Coding Practices
Error
- Location
- run.py:67
- Finding
- Database Connections Do Not Enforce Verified TLS## Vulnerability Details **File Location**: `run.py`, lines 67-69 and 94-96 **Vulnerability Type**: Database credentials and audit data transmitted without enforced, authenticated TLS **Risk Level**: High **Vulnerable Code**: ```python host, port, user, password, db = parse_dsn(dsn) # Security Fix: Use standard SSL conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db) ``` The same insecure connection configuration is used when reading logs: ```python host, port, user, password, db = parse_dsn(dsn) # Security Fix: Use standard SSL conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db) ``` ### Technical Analysis The code comments claim that standard SSL is used, but the `pymysql.connect` calls do not provide an SSL configuration, trusted certificate authority, hostname verification policy, or any mechanism requiring an encrypted connection. Consequently, the client does not explicitly enforce authenticated TLS. The connection transports a database username, password, and potentially sensitive audit messages. These messages are intended to record high-risk commands, errors, and agent activity. If the connection is established without verified TLS, an attacker with a suitable network position may intercept credentials or audit records. A connection that encrypts traffic without verifying the server identity would also remain exposed to an active machine-in-the-middle attack. ### Attack Path 1. The skill obtains a TiDB DSN from environment variables, its local cache, or the provisioning API. 2. The skill connects to the remote database using `pymysql.connect` without requiring verified TLS. 3. An attacker obtains a network interception position, such as control of an untrusted network, compromised gateway, or malicious routing/DNS infrastructure. 4. The attacker observes or actively intercepts the database connection. 5. Depending on the server ...[truncated 745 chars]
- Remediation
- ## Remediation Suggestions - Require TLS explicitly in both database connection paths. - Configure PyMySQL with a trusted CA certificate and certificate and hostname verification, for example through an appropriate `ssl` configuration supported by the deployed PyMySQL version. - Reject connections when TLS negotiation or certificate validation fails; do not silently fall back to plaintext. - Use the TiDB provider's documented CA bundle and secure connection parameters. - Apply the same connection factory and verified-TLS policy to both `log_event` and `read_logs` to prevent configuration drift. - Use a narrowly privileged database account that can access only the required schema and operations. - Add an integration test that verifies encryption is active and that an untrusted or hostname-mismatched certificate is rejected. - Remove or correct the misleading `Security Fix` comments until verified TLS is actually enforced.
