/

CVE-2026-40315

Severity:

CRITICAL RISK

(9.8)

SQL Injection in PraisonAI SQLiteConversationStore Table

CVE-2026-40315

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Unauthorized Data Access and Query Manipulation

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

PraisonAI's SQLiteConversationStore previously concatenated the configurable table_prefix value directly into SQL queries using f-strings, enabling SQL identifier injection.

An attacker who can influence configuration inputs (e.g., via from_yaml or from_dict) may inject arbitrary SQL fragments into query structure, leading to internal schema disclosure and full tampering of query results.

Affected context

This vulnerability occurs in PraisonAI deployments that use the SQLiteConversationStore with a configurable table_prefix value.

It is relevant when:

  • Configuration is loaded from external or semi-trusted sources (e.g., YAML files, dictionaries, user-supplied configs).
  • The table_prefix is not strictly controlled, validated, or constrained to a safe format (such as a fixed, alphanumeric identifier).
  • The application relies on SQLite for storing conversation data and constructs SQL queries dynamically using f-strings or string concatenation.

In such setups, the configuration pipeline (e.g., config.py → factory.py → sqlite.py) becomes a propagation path for untrusted data into SQL query construction.

Exploit preconditions

  • Attack surface: Configuration loading interfaces such as from_yaml, from_dict, environment-driven config, or any mechanism that lets an attacker influence table_prefix.
  • Required access: Ability to modify or submit configuration input consumed by PraisonAI (e.g., write access to config files, config management systems, or user-facing config endpoints).
  • Trigger point: Execution of SQLiteConversationStore operations that build SQL statements using the attacker-controlled table_prefix in table names or other SQL identifiers.
  • Why exploitation is possible: SQL identifiers are concatenated via f-strings instead of being constructed from validated, constrained values or safe identifier-building routines. Since SQL identifier positions cannot be safely parameterized with standard query parameters, direct insertion of untrusted strings enables injection of additional SQL fragments that alter query structure.

Why this happens

The underlying issue is improper neutralization of special elements in SQL commands, mapped to CWE-89: SQL Injection.

Instead of treating table_prefix as a strictly controlled identifier and enforcing a safe, narrow character set, the application:

  • Accepts table_prefix from configuration sources that may be influenced by an attacker.
  • Propagates this value through the configuration pipeline without validation.
  • Concatenates it directly into SQL query strings via f-strings in sqlite.py.

This pattern allows untrusted data to be interpreted as part of the SQL grammar (e.g., injecting additional identifiers, operators, or entire clauses) rather than as a simple, inert identifier token.

Potential impact

  • Unauthorized reading of internal SQLite metadata tables such as sqlite_master.
  • Disclosure of database schema details, including table and index names and structures.
  • Manipulation of query results via injected UNION or other query-modifying constructs.
  • Bypassing application-level access controls by querying data not normally exposed.
  • Corruption or tampering of stored conversation data if write-capable queries are affected.
  • Facilitation of further attacks through detailed knowledge of the internal schema.

General mitigation guidance

Effective mitigation focuses on eliminating the ability for untrusted configuration values to influence SQL syntax and on strictly controlling identifier construction.

Pattern-based mitigations include:

  • Constrain configuration values: Treat fields like table_prefix as internal, non-user-controllable settings. Where configurability is necessary, restrict them to a safe pattern (e.g., ^[A-Za-z0-9_]+$) and enforce maximum length.
  • Centralize identifier validation: Implement a single utility for constructing SQL identifiers that:
  • Validates inputs against a strict whitelist of characters.
  • Rejects or normalizes any value containing SQL metacharacters (quotes, semicolons, whitespace control, comment markers).
  • Prefer fixed schema design: Use a fixed set of table names where possible instead of dynamic prefixes, reducing the attack surface for identifier manipulation.
  • Segment configuration trust: Treat configuration sources as untrusted by default and apply the same validation and sanitization rules as for other user inputs.
  • Least-privilege database usage: Operate with minimal database privileges necessary for the application, so even if queries are influenced, the scope of damage is reduced.

How teams detect issues like this

High-level detection can combine static inspection, dynamic testing, and process controls:

  • Static analysis: Configure SAST or linters to flag:
  • Direct string interpolation (f-strings, + concatenation) in SQL query construction.
  • Use of configuration-derived values in query strings without passing through a validation layer.
  • Code review signals:
  • Dynamic table or column name construction that includes unvalidated config or user input.
  • Queries assembled across multiple functions where data flows from config loading to SQL execution.
  • Policy enforcement:
  • Enforce patterns like "all SQL queries using string interpolation must call a shared identifier-escaper or validator."
  • Require security review for any code that builds SQL dynamically, especially around identifiers.
  • Runtime and testing approaches:
  • Use security-focused integration tests that feed malformed or malicious table_prefix values and verify that queries fail safely rather than execute.
  • Monitor logs for unexpected references to internal tables like sqlite_master originating from application queries.

Sources

SourceLink
github.comgithub.com/MervinPraison/PraisonAI/commit/0accebb2e3c3ec2fca66bbea0444fb7a35f0b4ef
github.comgithub.com/MervinPraison/PraisonAI/security/advisories/GHSA-x783-xp3g-mqhp

Frequently asked

questions

It can be, if configuration input (for example via from_yaml or a configuration API) is exposed to remote users or integrated external systems. If only trusted administrators can modify configuration and no external party can influence table_prefix, the practical exploitability is reduced but still depends on operational controls.

The attacker must be able to influence or control the configuration that sets table_prefix. This could involve write access to configuration files, control over configuration management pipelines, or access to any interface that feeds data into the configuration loading mechanisms.

The safest approach is to prevent untrusted data from ever influencing SQL syntax. Concretely, make table_prefix an internal, non-user-controlled setting or strictly validate it against a narrow, safe character set and length, and ensure all dynamic identifiers are built only from such validated values.

Adopt a defensive development policy that:

  • Treats configuration as potentially untrusted input.
  • Forbids direct string interpolation for SQL query construction, especially for identifiers.
  • Uses centralized validation utilities for any dynamic SQL components.
  • Integrates static analysis and security review steps into the development and CI/CD process to detect injection-prone patterns early.
Find out what's already
exploitable in your codebase.