T09 · Insecure Skill Coding Practices
Error
- Location
- debug_createdoc.py:9
- Finding
- Hard-Coded SiYuan API Token Transmitted over Unencrypted HTTP<![CDATA[ ## Vulnerability Details **File Locations**: - `debug_createdoc.py:9-29` - `test_create_alt.py:12-32` - `test_create_real.py:12-32` **Vulnerability Type**: Hard-coded credential and cleartext credential transmission **Risk Level**: High ### Vulnerable Code The same credential and HTTP endpoint are embedded in all three scripts: ```python API_URL = "http://192.168.1.6:6811" TOKEN = "xz1eblvxst0zqcpm" headers = { 'Authorization': f'Token {TOKEN}', 'Content-Type': 'application/json' } ``` The credential is then transmitted in authenticated requests: ```python response = requests.post( f'{API_URL}/api/notebook/lsNotebooks', headers=headers, json={}, timeout=10 ) ``` The scripts subsequently reuse the same authorization header for notebook enumeration, document listing, document creation, block appending, and verification requests. ### Technical Analysis A credential that appears to be an operational API token is committed directly to three executable scripts. It is not a placeholder and is paired with a specific private-network SiYuan endpoint. This creates two independent exposure channels: 1. **Credential disclosure at rest:** Any person or process that can access the package, source repository, archives, build artifacts, or repository history can recover the token. 2. **Credential disclosure in transit:** The endpoint uses plain HTTP. The `Authorization` header therefore receives no TLS confidentiality or server authentication. An attacker able to observe or manipulate traffic on the relevant network path can capture or alter authenticated requests. The scripts are test and debugging utilities, so embedding a live credential is not necessary for the Skill's declared functionality and exceeds the minimum privilege needed for distributable test fixtures. Tests should use mocked services or credentials supplied explicitly at runtime. ### Attack Path 1. An attacker obtains a copy of the Skill package, a repository clone ...[truncated 1494 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Immediately revoke and rotate the exposed token on the SiYuan instance. 2. Remove the token from: - `debug_createdoc.py` - `test_create_alt.py` - `test_create_real.py` - All repository history, release archives, logs, and copied artifacts where feasible. 3. Read credentials only from runtime secret sources: ```python import os API_URL = os.environ["SIYUAN_API_URL"] TOKEN = os.environ["SIYUAN_API_TOKEN"] ``` 4. Do not provide a real endpoint as a test default. Require explicit test configuration and fail closed when it is absent. 5. Replace live API calls in automated tests with a mocked HTTP server or request-mocking library. 6. Require HTTPS for non-loopback endpoints and retain certificate verification. 7. If local HTTP support is necessary for SiYuan, restrict it to loopback addresses such as `127.0.0.1`, `::1`, or `localhost`. 8. Add automated secret scanning to pre-commit and CI workflows. 9. Add test safeguards that require explicit confirmation before modifying a real notebook. 10. Review server logs for unexpected use of the exposed token and investigate unauthorized document changes. ]]>
