T09 · Insecure Skill Coding Practices
- Location
scripts/strategy_engine.py:179- Finding
Local Financial Records Are Stored Without Explicit Restrictive Filesystem Permissions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/strategy_engine.py:179-184; related sensitive schema inscripts/import_eastmoney_pingzhongdata.py:336-379
Vulnerability Type: Insecure permissions for locally stored sensitive financial data
Risk Level: MediumVulnerable Code
python def connect_db(db_path: Path = DEFAULT_DB_PATH) -> sqlite3.Connection: db_path.parent.mkdir(parents=True, exist_ok=True) connection = sqlite3.connect(db_path) connection.row_factory = sqlite3.Row importer.init_db(connection) return connectionThe resulting database contains financial account state and transaction history:
sql CREATE TABLE IF NOT EXISTS strategy_accounts ( account_id TEXT NOT NULL, fund_code TEXT NOT NULL, fund_type TEXT NOT NULL DEFAULT 'equity_fund', cash_pool REAL NOT NULL DEFAULT 0, position_units REAL NOT NULL DEFAULT 0, avg_cost_price REAL, note TEXT, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, PRIMARY KEY (account_id, fund_code) ); CREATE TABLE IF NOT EXISTS strategy_trades ( id INTEGER PRIMARY KEY AUTOINCREMENT, account_id TEXT NOT NULL, fund_code TEXT NOT NULL, trade_date TEXT NOT NULL, trade_time_local TEXT, trade_type TEXT NOT NULL, direction TEXT NOT NULL, gross_amount REAL NOT NULL DEFAULT 0, price REAL, units REAL NOT NULL DEFAULT 0, fee_rate_pct REAL, fee_amount REAL NOT NULL DEFAULT 0, cash_delta REAL NOT NULL, units_delta REAL NOT NULL, note TEXT, created_at TEXT NOT NULL );Technical Analysis
The Skill creates the database directory using
Path.mkdir()and opens or creates the SQLite database throughsqlite3.connect(), but it does not explicitly enforce restrictive permissions on either resource.Consequently, access permissions are inherited from the process umask. Under a permis ...[truncated 2338 chars]
- Remediation
View remediation
Remediation Suggestions
-
Create the default storage directory with owner-only permissions:
python db_path.parent.mkdir(mode=0o700, parents=True, exist_ok=True) db_path.parent.chmod(0o700) -
Create a new database atomically with mode
0600, or immediately enforce that mode after creation:python import os if not db_path.exists(): fd = os.open(db_path, os.O_CREAT | os.O_EXCL | os.O_RDWR, 0o600) os.close(fd) db_path.chmod(0o600) connection = sqlite3.connect(db_path) -
Before opening an existing database, verify that it is a regular file, is owned by the expected user, and is not a symbolic link.
-
Reject databases in world-writable or untrusted shared directories unless the user explicitly acknowledges the risk.
-
Detect and repair group or world access on existing databases. If safe remediation is not possible, stop with a clear error rather than silently processing sensitive records.
-
Avoid printing an unnecessary absolute database path in routine output, particularly in shared logs.
-
Document that the SQLite database contains sensitive financial information and should not be committed to source control, placed in shared storage, or backed up without appropriate access controls and encryption.
-
