T09 · Insecure Skill Coding Practices
Warning
- Location
- SKILL.md:43
- Finding
- Unsafe Privileged Modification of a Shared Python Installation<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 43–49 **Vulnerability Type**: Unsafe privileged file replacement **Risk Level**: Medium ### Vulnerable Code ```bash # 3. 复制(cpython-311 后缀必须匹配目标 Python 小版本) sudo cp /usr/lib64/python3.11/lib-dynload/_sqlite3.cpython-311-x86_64-linux-gnu.so \ /usr/local/lib/python3.11/lib-dynload/ # 4. 验证 + 重启服务 <venv>/bin/python3 -c "import sqlite3; print(sqlite3.sqlite_version)" sudo systemctl restart <service> ``` ### Technical Analysis The instructions use root privileges to copy a native Python extension from an RPM-managed interpreter into a separately built, system-wide Python installation. Compatibility is assessed only through the Python minor version and filename suffix. The procedure does not verify: - The source file's package provenance or integrity. - The target interpreter's complete SOABI and build configuration. - Architecture and compiler compatibility beyond the hard-coded filename. - Linked native library compatibility. - Whether a destination file already exists and will be overwritten. - Destination ownership and permissions. - Whether other applications depend on the shared `/usr/local` interpreter. Native CPython extensions execute within the interpreter process and must match its ABI and linked-library expectations. A mismatch can produce import failures, interpreter crashes, memory corruption, or undefined behavior. Because the destination is shared rather than isolated to the virtual environment, the modification may affect multiple applications. ### Attack Path 1. An operator follows the documented repair procedure with `sudo`. 2. The source extension is incompatible, modified, or otherwise untrusted. 3. `sudo cp` places or overwrites `_sqlite3` in the shared `/usr/local` Python installation. 4. The verification command or restarted service imports `sqlite3`. 5. The interpreter loads the copied native extension into its process. 6. An incompatible module causes ...[truncated 686 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Prefer rebuilding Python with the required development libraries or recreating the virtual environment with the complete RPM-packaged interpreter. - Do not modify a shared interpreter until the repair has been tested in an isolated environment. - Verify the source package and file integrity using the package manager, such as `rpm -qf` and `rpm -V`. - Compare the complete SOABI using `sysconfig.get_config_var("SOABI")`, not only the Python minor version. - Validate architecture, build flags, and native dependencies with tools such as `file`, `readelf`, and `ldd`. - Refuse to overwrite an existing destination module without an explicit backup and operator confirmation. - Use `install` with explicit ownership and permission settings rather than an unrestricted `cp`. - Test imports and application behavior in a staging environment before restarting a production service. - Document a rollback procedure that restores the original module or interpreter installation. ]]>
