Skip to main content
Menu
Advisories

Injection via non-String metadata filter values in the pgvector, MariaDB, Milvus, MongoDB Atlas and Chroma embedding stores

GHSA-6WGF-C23J-FJ2VPublished Updated GitHub

Description

Several embedding stores built the query for a metadata Filter by writing the filter values into the query text. A value that was not a String was written with toString(), without escaping. The filter API accepts any object as a value: new IsEqualTo(String, Object), new IsIn(String, Collection<?>) and MetadataFilterBuilder.isIn(Collection<?>). So an application that passes loosely typed data into a filter lets that data change the query. Examples of such data are a List or Map parsed from request JSON, or from LLM tool output.

Details

  • langchain4j-pgvector: in isIn / isNotIn, a non-String value was written as ' + value.toString() + ', without escaping. A nested list such as isIn(List.of(List.of("x') or 1=1 --"))) closes the literal. Scalar comparisons were not affected (the query failed). Before 1.11.0, isIn / isNotIn did not escape String values either, so a plain String such as x') or 1=1 -- closed the literal too. This affects all versions before 1.11.0, including the 1.5.x line up to 1.5.3-beta11.
  • langchain4j-mariadb: a value that was not a String, UUID or Collection was written with toString(), without quotes. Examples are a Map whose text starts with a JDBC escape ({fn ...}), or a StringBuilder. This applies to comparison filters and to isIn / isNotIn.
  • langchain4j-milvus and langchain4j-milvus-v2: non-String values were written into the filter expression with toString(), without quotes.
  • langchain4j-mongodb-atlas and langchain4j-chroma: IsEqualTo was written in the short form {key: value}, so a Map value such as {"$ne": "x"} was read as a query operator.

The affected operations are search (including pgvector hybrid search) and removeAll(Filter).

These are not affected:

  • Applications that build filters only from String, number, UUID or Boolean values, for example with the typed MetadataFilterBuilder methods. Exception: langchain4j-pgvector before 1.11.0, see above.
  • Filters built by LanguageModelSqlFilterBuilder: it only produces String, Long and Double values.

Impact

For an application that passes untrusted, loosely typed values into a metadata filter:

  • Reading other tenants' or users' rows through search. An injected or overrides the conditions the application added with and(...).
  • Deleting all rows through removeAll(Filter).

Patches

Fixed in these versions (langchain4j-milvus-v2 exists only since 1.19.0-beta29):

  • 1.23.0-beta33
  • 1.19.4-beta29
  • 1.11.12-beta19
  • 1.5.4-beta11

The fix is the same in all of them:

  • pgvector and MariaDB bind filter values as JDBC parameters.
  • Milvus and Milvus v2 accept only supported value types.
  • MongoDB Atlas and Chroma write equality with an explicit $eq.

In addition, langchain4j-core 1.23.0 checks filter values when a filter is created. This check is not in the backports, because it is a breaking change. It accepts only:

  • String, UUID and Boolean
  • numbers: Integer, Long, Float, Double, Byte, Short, BigInteger and BigDecimal
  • enums
  • date/time values

This also protects other embedding stores, including stores outside this repository.

Workarounds

  • Pass only String, number, UUID or Boolean values into metadata filters. On langchain4j-pgvector before 1.11.0 this is not enough, because String values in isIn / isNotIn are not escaped there either: upgrade.
  • Do not pass collections, maps, JsonNodes or other objects from request data or LLM output into a filter without converting each value first.

References

Affected versions

References

GitHub · langchain4j/langchain4j