Skip to content

fix(llama-index-vector-stores-db2): escape SQL string literals to prevent injection#21590

Open
pwilkin wants to merge 1 commit intorun-llama:mainfrom
pwilkin:fix-db2-sqli
Open

fix(llama-index-vector-stores-db2): escape SQL string literals to prevent injection#21590
pwilkin wants to merge 1 commit intorun-llama:mainfrom
pwilkin:fix-db2-sqli

Conversation

@pwilkin
Copy link
Copy Markdown

@pwilkin pwilkin commented May 7, 2026

Summary

Fixes SQL injection vulnerabilities in the IBM Db2 vector store (llama-index-vector-stores-db2). This package was added after CVE-2025-1793 (multi-store SQLi) was patched, but was not included in that fix — it contains the same vulnerable pattern of f-string interpolation of user-controlled values into SQL.

Vulnerability Details

Three sinks are patched:

  1. delete(ref_doc_id) at base.py:333

    • ddl = f"DELETE FROM {self.table_name} WHERE doc_id = '{ref_doc_id}'"
    • User-controlled ref_doc_id is interpolated without escaping.
  2. query() via _stringify_list(query.doc_ids) at base.py:117 + 349

    • where_str = f"doc_id in {_stringify_list(query.doc_ids)}"
    • Items in the list are wrapped in single quotes without escaping.
  3. query() via _append_meta_filter_condition at base.py:271

    • filter_str = f"JSON_VALUE(..., '$.{filter_item.key}') = '{filter_item.value}'"
    • Both key and value are interpolated without escaping.

Fix

Applied _escape_str() (existing helper) to all user-controlled string values interpolated into SQL. Also corrected _escape_str() to use Db2-standard quote-doubling ('') instead of backslash escaping, which Db2 does not support.

Verification

  • PoC confirmed all three sinks are exploitable in main
  • PoC re-run after patch confirms all three sinks are closed
  • Legitimate operations (delete, query with doc_ids, query with filters) still work correctly

Related

…vent injection (CVE-2025-1793 follow-up)

The DB2 vector store was added after CVE-2025-1793 was fixed but contained
the same vulnerable pattern: f-string interpolation of user-controlled values
into SQL without escaping.

Three sinks are patched:
1. delete(ref_doc_id) – base.py:333
2. query() via _stringify_list(query.doc_ids) – base.py:117+349
3. query() via _append_meta_filter_condition – base.py:271

Also fixes _escape_str to use Db2-standard quote-doubling ('' instead of \')
which is the correct escaping mechanism for IBM Db2 SQL string literals.

Fixes huntr.dev report (TODO: fill in report ID after submission).
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 7, 2026
@pwilkin
Copy link
Copy Markdown
Author

pwilkin commented May 7, 2026

Note: some other stores added after the previous CVE fix are also vulnerable since they have the same lack-of-sanitation bug (azurecosmos, alibabacloud-openserach, azureaisearch, dashvector), but they're not SQL stores so likely less severe (still should probably be patched).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant