/

CVE-2026-41496

Severity:

HIGH RISK

(8.1)

SQL Injection in PraisonAI Conversation Store Backends

CVE-2026-41496

Modified

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Arbitrary SQL Execution and Data Compromise

Severity:

HIGH RISK

(8.1)

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 conversation storage backends contained multiple SQL injection flaws where unvalidated table and schema identifiers were interpolated directly into SQL f-strings.

If an attacker can influence configuration values such as table_prefix or schema, they can craft malicious identifiers that alter queries, manipulate data, or execute arbitrary SQL commands across several supported databases.

Affected context

This vulnerability affects PraisonAI deployments that use any of the non-default or sibling conversation store backends where configuration values are used to dynamically construct SQL.

Impacted backends include:

  • MySQL
  • PostgreSQL
  • Async SQLite/MySQL/PostgreSQL variants
  • Turso
  • SingleStore
  • Supabase
  • SurrealDB

The issue is present when user-controllable or externally supplied values are passed into table_prefix or PostgreSQL schema settings and then embedded directly into SQL statements without robust validation or safe identifier handling.

Exploit preconditions

  • Attack surface: Application-layer configuration and API inputs that influence conversation storage, such as:
  • Configuration files or environment variables
  • Tenant, workspace, or project identifiers mapped to table_prefix
  • Parameters or metadata that determine schema or table names
  • Required access:
  • Ability to set or modify table_prefix and/or schema (directly or indirectly)
  • In some deployments, this could be via administrative panels, multi-tenant onboarding flows, or untrusted automation that maps user input to these values.
  • Trigger point:
  • Any operation that causes the conversation store to:
  • Create tables (DDL)
  • Read/write conversations (DML)
  • Perform migrations or housekeeping queries
  • In postgres.py specifically, schema is used in DDL, making initialization and setup sequences potential triggers.
  • Why exploitation is possible:
  • The affected backends embed table_prefix and schema directly into SQL f-strings, treating them as trusted identifiers.
  • No strict validation, quoting, or safe identifier construction is applied, allowing crafted values to break out of the intended identifier context and inject arbitrary SQL fragments.

Why this happens

The root cause is a classic SQL injection pattern, captured by CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').

Instead of treating table_prefix and schema as untrusted input that must be constrained to safe identifier characters, the code builds SQL statements using Python f-strings such as:

  • Directly embedding table names with prefixes
  • Composing DDL and DML statements that concatenate user-influenced identifiers

This pattern bypasses parameterization, which only safely handles values, not identifiers. As a result, any attacker-controlled content that reaches table_prefix or schema can introduce SQL syntax, inject additional clauses, or terminate and append statements. The issue is amplified by the presence of dozens of injection points across multiple backend modules, all reusing the same unsafe composition pattern.

Potential impact

  • Full read access to conversation histories and related metadata stored in the affected databases
  • Unauthorized modification or deletion of conversation data, including tampering, truncation, or bulk wipes
  • Creation or alteration of tables, schemas, or other database objects (especially in the PostgreSQL backend where schema is used in DDL)
  • Lateral access to other application data stored in the same database instance, depending on schema design and privileges
  • Potential execution of database-specific features (e.g., functions, procedures, extensions) that can escalate to broader system compromise in misconfigured environments
  • Data corruption that undermines application integrity, auditing, or multi-tenant isolation guarantees

General mitigation guidance

Effective mitigation focuses on eliminating dynamic, untrusted string interpolation in SQL and constraining identifiers at the boundary:

  • Treat identifiers as untrusted input by default:
  • Apply strict allow-lists for table_prefix, schema, and similar configuration values (e.g., alphanumeric with underscores only, bounded length).
  • Reject or sanitize any value that is not a valid identifier before it reaches the database layer.
  • Use safe identifier construction mechanisms:
  • Prefer database or driver utilities that quote and escape identifiers correctly where available.
  • Centralize identifier building into a small set of helper functions that enforce consistent validation and quoting rules.
  • Minimize dynamic SQL:
  • Design schema and table layouts to reduce the need for runtime-generated identifiers (e.g., use a single table with a tenant_id column instead of per-tenant tables when appropriate).
  • Avoid building DDL from request-time input; perform schema creation and migration via controlled deployment processes.
  • Enforce least privilege at the database level:
  • Use separate accounts with minimal rights, limiting the ability of the application to perform dangerous operations such as arbitrary DDL or cross-schema access.
  • Segment multi-tenant data carefully so that even if one query is abused, blast radius remains constrained.
  • Harden configuration management:
  • Restrict who and what can modify environment variables, configuration files, and admin interfaces that feed into table_prefix and schema values.
  • Treat these settings as sensitive, subject to the same governance as credentials and connection strings.

How teams detect issues like this

To detect and monitor for this class of vulnerabilities:

  • Static analysis and code scanning:
  • Scan for SQL construction patterns using f-strings, string concatenation, or format() that include variables like table_prefix, schema, or other dynamic identifiers.
  • Add custom rules to static analysis tools to flag queries that do not use parameterization and that interpolate potentially user-controlled input into SQL.
  • Targeted code review:
  • Review all database backend implementations, focusing on:
  • Custom conversation store classes
  • Shared helper functions that generate SQL
  • Modules handling multi-tenant or per-customer table/schema patterns
  • Look specifically for places where identifiers are built from configuration or request-derived data without validation.
  • Runtime monitoring and logging:
  • Enable detailed query logging in development and staging environments to surface unexpected SQL patterns or malformed identifiers.
  • Watch for anomalous SQL activity, such as unexpected DDL operations or queries referencing unrecognized tables or schemas.
  • Security testing and fuzzing:
  • Incorporate targeted SQL injection tests into CI pipelines, especially around configuration-driven features (e.g., tenant creation, workspace naming).
  • Use automated tools or scripts that systematically inject special characters into configuration fields mapped to table or schema names.

Sources

SourceLink
github.comgithub.com/MervinPraison/PraisonAI/security/advisories/GHSA-rg3h-x3jw-7jm5

Frequently asked

questions

Exploitability depends on whether an attacker can influence table_prefix or schema values, directly or indirectly. In environments where these values are derived from tenant names, workspace identifiers, or other user-supplied labels, the exposure can be broad. In locked-down deployments where only trusted operators can change these settings, the risk is narrower but still present if those paths can be abused.

No. The attacker only needs a way to feed crafted values into the application layer that are subsequently used as table_prefix or schema. The database itself sees these requests as coming from the application, so exploitation is possible without direct database credentials, assuming the application account has sufficient privileges.

The safest pattern is to stop interpolating unvalidated identifiers into SQL strings. Enforce strict validation and normalization of identifier-like inputs, centralize safe identifier construction, and redesign schema usage to minimize dynamic table or schema creation. Wherever possible, use parameterized queries for values and driver- or ORM-level mechanisms for handling identifiers.

Prevention relies on a combination of secure coding practices and guardrails: adopt coding standards that ban raw f-string SQL with untrusted input, use linters and static analysis rules to enforce parameterization, restrict configuration values that influence SQL structure, and subject all database-related code to focused security review. Regular training on SQL injection patterns and centralized database access layers can further reduce the risk of regressions.

Find out what's already
exploitable in your codebase.