GitHub Security Advisory: GHSA-x783-xp3g-mqhp
Package: PraisonAI (PIP)
Severity: MODERATE (CVSS 0.0)
CWE: CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Vulnerable versions: < 4.5.133
Patched in: 4.5.133

Summary: PraisonAI: SQLiteConversationStore didn't validate table_prefix when constructing SQL queries

Details:
### Summary

The `table_prefix` configuration value is directly used to construct SQL table identifiers without validation.

If an attacker controls this value, they can manipulate SQL query structure, leading to unauthorized data access (e.g., reading internal SQLite tables such as `sqlite_master`) and tampering with query results.

---

### Details
This allows attackers to inject arbitrary SQL fragments into table identifiers, effectively altering query execution.

This occurs because `table_prefix` is passed from configuration (`from_yaml` / `from_dict`) into `SQLiteConversationStore` and directly concatenated into SQL queries via f-strings:

```python
sessions_table = f"{table_prefix}sessions"
```

This value is then used in queries such as:

```sql
SELECT * FROM {self.sessions_table}
```

Since SQL identifiers cannot be safely parameterized and are not validated, attacker-controlled input can modify SQL query structure.



The vulnerability originates from configuration input and propagates through the following flow:

* **Source:** [config.py](https://github.com/MervinPraison/PraisonAI/blob/fde17acdc89cafd97ff49e9ddc81777b4445850f/src/praisonai/praisonai/persistence/config.py)
  (`from_yaml` / `from_dict`) accepts external configuration input

* **Propagation:** [factory.py](https://github.com/MervinPraison/PraisonAI/blob/fde17acdc89cafd97ff49e9ddc81777b4445850f/src/praisonai/praisonai/persistence/factory.py)
  (`create_stores_from_config`) passes `conversation_options` without validation

* **Sink:** [sqlite.py](https://github.com/MervinPraison/PraisonAI/blob/5ed5f1a6a96c829527abed15ac6d6166aafc6abd/src/praisonai/praisonai/persistence/conversation/sqlite.py)
  Constructs SQL queries using f-strings with identifiers derived from `table_prefix`

As a result, attacker-controlled `table_prefix` is interpreted as part of the SQL query, enabling injection into table identifiers and altering query semantics.

### PoC

#### 1. Exploit Code
The PoC demonstrates that attacker-controlled `table_prefix` is not treated as a simple prefix but as part of the SQL query, allowing full manipulation of query structure.
```python
#!/usr/bin/env python3
"""
PoC: SQL identifier injection via SQLiteConversationStore.table_prefix

This demonstrates query-structure manipulation when table_prefix is attacker-controlled.
"""

import os
import tempfile

from praisonai.persistence.conversation.sqlite import SQLiteConversationStore
from praisonai.persistence.conversation.base import ConversationSession


def run_poc() -> int:
    fd, db_path = tempfile.mkstemp(suffix=".db")
    os.close(fd)

    try:
        print(f"[+] temp db: {db_path}")

        # 1) Create normal schema and insert one legitimate session.
        normal = SQLiteConversationStore(
            path=db_path,
            table_prefix="praison_",
            auto_create_tables=True,
        )
        normal.create_session(
            ConversationSession(
                session_id="legit-session",