Summary
PraisonAI contained a critical SQL injection vulnerability where the get_all_user_threads function built raw SQL queries with f-strings, directly interpolating unescaped thread IDs.
An attacker able to store a crafted thread ID via update_thread could trigger arbitrary SQL execution when the thread list is loaded, potentially gaining full database access.
Affected context
The vulnerability occurs in PraisonAI's data access layer responsible for listing user threads, specifically in the get_all_user_threads function.
The issue manifests when:
- Thread identifiers from persistent storage are treated as trusted values
- Raw SQL queries are constructed via Python f-strings or string concatenation
- No parameterized queries or escaping are applied to the thread IDs before query execution
This pattern can appear in any environment where PraisonAI is deployed with a relational database backend.
Exploit preconditions
- Attack surface: Application backend functions that load user thread lists from the database.
- Required access: Ability to invoke update_thread or any feature that can persist or modify thread IDs (e.g., via authenticated API or compromised internal process).
- Trigger point: Any operation that calls get_all_user_threads and executes the dynamically constructed SQL containing the malicious thread ID.
- Why exploitation is possible: The application directly embeds thread IDs into SQL statements using f-strings without parameterization or sanitization, allowing attacker-controlled content to be interpreted as SQL syntax.
Why this happens
This vulnerability stems from constructing SQL queries by concatenating or interpolating untrusted data into query strings, instead of using parameterized queries.
In PraisonAI, get_all_user_threads uses Python f-strings with thread IDs retrieved from the database, assuming they are safe. However, because update_thread allows an attacker to store arbitrary content as a thread ID, that content can later be reinterpreted as part of the SQL statement.
This aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where the failure to neutralize metacharacters in input allows attackers to alter the structure and logic of database queries.
Potential impact
- Execution of arbitrary SQL commands against the application database
- Reading, modifying, or deleting sensitive user and application data
- Creation of new privileged accounts or escalation of existing privileges at the application or database layer
- Destruction or corruption of database tables, leading to denial of service
- Bypassing application-level authorization by directly manipulating data relationships
General mitigation guidance
Mitigation should focus on eliminating direct string-based query construction and enforcing strict separation between SQL code and data:
- Use parameterized queries (prepared statements) provided by the database driver or ORM for all dynamic values, including identifiers where supported.
- Avoid constructing SQL with f-strings, string concatenation, or format operations that include any value that has ever been influenced by users or external systems.
- Introduce strict validation and normalization for identifiers such as thread IDs (e.g., enforcing specific formats or types) before they are used in database operations.
- Centralize database access in a well-reviewed data access layer where secure query patterns are enforced by default.
- Apply least-privilege principles to database accounts so that even if a query is abused, the scope of damage is constrained.
How teams detect issues like this
Organizations can detect similar issues by:
- Running static analysis rules that flag raw SQL construction using string interpolation (f-strings, %, .format, or concatenation) with variable content.
- Reviewing code paths where identifiers (IDs, keys, names) are persisted and later reused in SQL statements, ensuring parameterization at every step.
- Implementing secure coding guidelines and pre-commit or CI checks that disallow direct SQL string composition except in vetted, parameterized helper functions.
- Using dynamic application security testing (DAST) or interactive testing to probe API endpoints like update_thread and list-threads for SQL injection behavior.
- Logging anomalous SQL errors and patterns (e.g., syntax errors containing user-controlled fragments) and monitoring for suspicious query activity.

