Security advisory GHSA-x783-xp3g-mqhp: PraisonAI: SQLiteConversationStore didn't validate table_prefix when constructing SQL queries
Package: praisonai (pypi), vulnerable version: 4.5.132, fixed in: 4.5.133
CWE: CWE-89
Files changed by the fix:
src/praisonai/praisonai/gateway/server.py
src/praisonai/praisonai/persistence/conversation/sqlite.py

Fix diff:
diff --git a/.github/praisonai-issue-triage.yaml b/.github/praisonai-issue-triage.yaml
index dfd346e67..d57e06747 100644
--- a/.github/praisonai-issue-triage.yaml
+++ b/.github/praisonai-issue-triage.yaml
@@ -40,7 +40,7 @@ steps:
     action: |
       Implement the changes required to solve the issue:
       1. Review the analyst's plan.
-      2. Check out a dedicated fix branch by calling `execute_command` with `command` set to `git checkout -b praisonai/issue-$ISSUE_NUMBER`. Do NOT provide a `cwd` argument.
+      2. Check out a dedicated fix branch by calling `execute_command` with `command` set to `git checkout -b praisonai/issue-{{ISSUE_NUMBER}}`. Do NOT provide a `cwd` argument.
       3. Carefully modify the necessary files in the repository using bash commands (e.g. `cat`, `sed`, `echo`, or small inline scripts). 
       4. Double-check your edits by inspecting the file outputs or running `git diff` to ensure you changed what was required.
     expected_output: "Confirmation that the git branch was successfully created and the files were reliably modified without syntax errors."
@@ -52,7 +52,7 @@ steps:
       1. Stage the files with `execute_command` where `command` is `git add .`. Do NOT provide a `cwd` argument.
       2. Commit the changes: `git commit -m "PraisonAI Automated Fix"`
       3. Push the branch to GitHub: `git push -u origin HEAD`
-      4. Create the Pull Request back to main: `gh pr create --title "Fix Issue $ISSUE_NUMBER" --body "Automated triage by PraisonAI Native Issue Triage." --head "praisonai/issue-$ISSUE_NUMBER" --base main`
-      5. Post a comment on the original issue letting the user know: `gh issue comment $ISSUE_NUMBER -b "I have autonomously analyzed the codebase and written a fix for this issue! I've opened a Pull Request for your review."`
+      4. Create the Pull Request back to main: `gh pr create --title "Fix Issue {{ISSUE_NUMBER}}" --body "Automated triage by PraisonAI Native Issue Triage." --head "praisonai/issue-{{ISSUE_NUMBER}}" --base main`
+      5. Post a comment on the original issue letting the user know: `gh issue comment {{ISSUE_NUMBER}} -b "I have autonomously analyzed the codebase and written a fix for this issue! I've opened a Pull Request for your review."`
     expected_output: "The URL of the successfully created Pull Request."
     dependencies: [analyze_issue, implement_fix]
diff --git a/src/praisonai/praisonai/gateway/server.py b/src/praisonai/praisonai/gateway/server.py
index c2842bb75..713238730 100644
--- a/src/praisonai/praisonai/gateway/server.py
+++ b/src/praisonai/praisonai/gateway/server.py
@@ -203,6 +203,7 @@ def __init__(
         """
         self.config = config or GatewayConfig(host=host, port=port)
         if hasattr(self.config, 'auth_token') and not self.config.auth_token:
+            import secrets
             self.config.auth_token = secrets.token_hex(16)
             logger.warning(
                 f"No auth_token provided for Gateway server. Generated temporary token: {self.config.auth_token}. "
diff --git a/src/praisonai/praisonai/persistence/conversation/sqlite.py b/src/praisonai/praisonai/persistence/conversation/sqlite.py
index 2a987a18d..c94eb3b94 100644
--- a/src/praisonai/praisonai/persistence/conversation/sqlite.py
+++ b/src/praisonai/praisonai/persistence/conversation/sqlite.py
@@ -46,6 +46,12 @@ def __init__(
             check_same_thread: SQLite check_same_thread parameter
         """
         self.path = path
+        
+        # Prevent SQL injection in table identifiers
+        import re
+        if not re.match(r'^[a-zA-Z0-9_]*$', table_prefix):
+            raise ValueError("table_prefix must contain only alphanumeric characters and underscores")
+            
         self.table_prefix = table_prefix
         self.sessions_table = f"{table_prefix}sessions"
         self.messages_table = f"{table_prefix}messages"