T09 · Insecure Skill Coding Practices
- Location
graph_store.py:9- Finding
Hard-Coded Cross-Workspace Database Path with Import-Time Filesystem Modification
- Content
View full analysis
Vulnerability Details
File Location:
graph_store.py, lines 9-15 and 214
Vulnerability Type: Hard-coded storage path and unexpected import-time side effect
Risk Level: Mediumpython GRAPH_DIR = r"C:\Users\37845\.qclaw\workspace\knowledge" DB_PATH = os.path.join(GRAPH_DIR, "graph.db") def _get_conn(): os.makedirs(GRAPH_DIR, exist_ok=True) conn = sqlite3.connect(DB_PATH) conn.execute("PRAGMA journal_mode=WAL")python # 初始化 init_db()Technical Analysis
The database location is hard-coded to a specific user's workspace rather than being supplied by the caller, derived from an approved application data directory, or resolved relative to the current workspace. This conflicts with the documented
knowledge/graph.dblocation and can cause data to be written across project or workspace boundaries.In addition,
init_db()is called at module scope. Importing the module therefore invokes_get_conn(), creates the configured directory, opens or creates the database, enables WAL mode, and initializes its schema without an explicit initialization request from the caller.On Windows, the code can modify another workspace when executed by an account that can access the configured path. On POSIX systems, the Windows-style path can be interpreted as an unintended relative path, creating files in an unexpected location. These operations remain limited to the privileges of the process running the module; the code does not independently elevate privileges.
Attack Path
- An application or agent imports
graph_store.pyto access its graph API. - The module-level
init_db()call executes automatically. init_db()calls_get_conn()._get_conn()creates the hard-coded directory and opens or createsgraph.db.- SQLite schema and WAL-related files are written to that location.
- If the path is shared with another project or user workspace accessible to the pr ...[truncated 660 chars]
- An application or agent imports
- Remediation
View remediation
Remediation Suggestions
- Remove the module-level
init_db()invocation and require explicit initialization by the application. - Accept the database path through a constructor, function argument, environment variable, or trusted configuration source.
- Use a safe default under a Skill-owned application data directory rather than a user-specific absolute path.
- Resolve and normalize the configured path before use, then verify that it remains within an approved workspace or data root.
- Reject paths that escape the approved root through absolute paths, symbolic links, or traversal components when untrusted callers can influence configuration.
- Apply restrictive filesystem permissions to the database directory and files.
- Document the exact storage location and import behavior.
- Add tests confirming that importing the module creates no files and that initialization cannot write outside the configured data root.
- Remove the module-level
