I'm worried that users could execute malicious code in my Elasticsearch cluser, e.g. delete the index or bring down the server by executing expensive queries. According to this answer, the problem does exist in theory.
Our Elasticsearch cluster is only accessible from our dotnet backend server and we use the Elasticssearch NEST client to execute our queries. Currently, the user input is used unchanged in our queries. For example:
var result = await nestClient.SearchAsync<Product>(search => search
.From(offset)
.Size(limit)
.Query(query => query
.MultiMatch(multiMatch => multiMatch
.Fields(fields => fields
.Field(product => product.Name)
.Field(product => product.Description))
.Operator(Operator.Or)
.Query(MALICIOUS_USER_INPUT)
)
)
);
I would expect that the NEST
client (or the low level Elasticsearch.Net
client) takes care of sanitizing the user input.
- Is this assumption correct? (link to proving documentation or source code highly appreciated)
- If the assumption is incorrect: What measures do I need to take to prevent users to inject malicious code in my Elasticsearch queries?