T09 · Insecure Skill Coding Practices
- Location
lib/storage.py:21- Finding
Client Database May Be Created with Overly Permissive Filesystem Permissions
- Content
View full analysis
Vulnerability Details
File Location:
lib/storage.py:21-24
Vulnerability Type: Insecure permissions on locally stored sensitive data
Risk Level: MediumVulnerable Code
python def init_db(): """Initialize database with schema""" DATA_DIR.mkdir(parents=True, exist_ok=True) conn = _get_conn()The CLI invokes this initialization path automatically when the database does not exist:
python def ensure_db(): """Ensure database exists""" if not DB_PATH.exists(): init_db()Technical Analysis
The automatic database initialization path creates the configured data directory without explicitly assigning restrictive permissions. It also opens the SQLite database without enforcing a restrictive process umask or changing the resulting database file permissions.
Consequently, permissions depend on the user's current umask. With a common umask of
022, the directory may be created with mode0755and the database with mode0644. Other local users could then traverse the directory and read the database.This differs from
setup.sh, which explicitly applies mode0700to the data directory on non-Windows platforms. Users can bypass that protection simply by running the CLI before running the setup script becauseensure_db()initializes the database automatically.The database can contain client names, contact names, email addresses, phone numbers, contract details, retainer information, notes, deliverable descriptions, assignments, and project history.
Attack Path
- A user invokes the CLI without first running
setup.sh. ensure_db()detects that the database does not exist and callsinit_db().init_db()creates the data directory and SQLite database using permissions derived from the ambient umask.- Under a permissive or standard umask, the database becomes readable by other local accounts.
- Another user on the same system accesses
~/.nex-deliverables/deliverables.dband ext ...[truncated 714 chars]
- A user invokes the CLI without first running
- Remediation
View remediation
Remediation Suggestions
- Create the application data directory with mode
0700. - Explicitly enforce the directory mode after creation because
mkdir(mode=...)does not correct an existing directory's permissions. - Create the SQLite database under a restrictive process umask such as
077. - Explicitly set the database file to mode
0600after creation. - Ensure SQLite journal, WAL, and shared-memory sidecar files receive equivalent protection.
- Apply the same permission controls inside
init_db()rather than relying onsetup.sh, because database initialization can occur independently.
Example hardening approach:
python import os def init_db(): DATA_DIR.mkdir(parents=True, exist_ok=True, mode=0o700) if os.name != "nt": DATA_DIR.chmod(0o700) old_umask = os.umask(0o077) try: conn = _get_conn() # Initialize schema and commit it here. finally: os.umask(old_umask) if os.name != "nt" and DB_PATH.exists(): DB_PATH.chmod(0o600)On Windows, use an appropriate access-control list that restricts the directory and database to the current user.
- Create the application data directory with mode
