Summary
dubydu sqlite-mcp up to version 0.1.0 contains a SQL injection vulnerability in the extract_to_json function, where the output_filename argument is used unsafely in SQL queries.
An attacker who can control this argument over a remote interface may inject arbitrary SQL, potentially leading to data exfiltration, modification, or disruption of the underlying SQLite database.
Affected context
The vulnerability resides in the extract_to_json function in src/entry.py within the sqlite-mcp project.
It manifests when user-controlled data, particularly the output_filename parameter, is incorporated into dynamically constructed SQL statements without adequate neutralization or parameterization.
This risk is most pronounced in deployments where extract_to_json is exposed through a network-accessible API, CLI service, or plugin interface that accepts untrusted input and executes queries against a SQLite database.
Exploit preconditions
- Attack surface: Any remote endpoint, API, or integration that forwards a caller-controlled output_filename into extract_to_json.
- Required access: Ability to invoke functionality that calls extract_to_json with a chosen output_filename value (e.g., HTTP request, RPC call, or plugin hook).
- Trigger point: The vulnerable code path that builds and executes a SQL query using the output_filename value in its structure or parameters.
- Why exploitation is possible: The application interpolates untrusted output_filename data into SQL commands without using parameterized queries or proper escaping, allowing crafted input to alter the intended query logic.
Why this happens
The core issue is unsafe construction of SQL queries using concatenation or string formatting with untrusted input from output_filename.
This behavior maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') and is closely related to CWE-74: Improper Neutralization of Special Elements in Output.
Instead of treating output_filename as data bound via parameters, the code incorporates it directly into SQL syntax, which allows attackers to inject additional SQL clauses or statements that the database interprets as legitimate commands.
Potential impact
- Unauthorized reading of data from SQLite tables beyond what the application normally exposes
- Modification or deletion of records, leading to data integrity issues or loss
- Creation or alteration of database schema elements such as tables or indexes
- Application-level denial of service via expensive or destructive queries
- Potential pivot to other vulnerabilities if application logic assumes database integrity
General mitigation guidance
Effective mitigation centers on treating all user-controlled strings as data, never as SQL syntax.
Recommended defensive patterns include:
- Using parameterized queries or prepared statements for all database interactions, including any parts influenced by output_filename.
- Avoiding dynamic SQL construction where possible; if dynamic behavior is required, constrain it to a fixed set of allowed values (e.g., whitelisting filenames or identifiers).
- Normalizing and validating output-related parameters against strict patterns (e.g., limiting to alphanumeric characters and known-safe separators, rejecting embedded SQL metacharacters).
- Encapsulating database access behind a minimal, well-reviewed API to reduce the number of places where SQL is constructed.
- Applying least-privilege principles to the database schema, such that the application account has only the minimum necessary permissions.
How teams detect issues like this
Detection typically involves a combination of code-centric and behavior-centric approaches:
- Static analysis rules that flag string concatenation or formatting used to build SQL queries, especially where variables like output_filename are involved.
- Manual code reviews focused on database access layers, looking for any non-parameterized queries or direct inclusion of user-controlled data in SQL.
- Runtime monitoring and logging of SQL statements to identify anomalous patterns (e.g., injected UNION, SELECT, or multi-statement constructs).
- Integration of security testing tools (SAST/DAST) into CI pipelines to automatically probe interfaces that accept output_filename-like parameters for SQL injection behavior.

