如何清理 Elasticsearch 自动生成的 ID?

How to sanitize Elasticsearch autogenrated ID?

我想在调用服务器之前验证我的 Elasticsearch ID。我四处寻找,想知道是否有办法检查请求的 ID 是否具有正确的格式。我不确定这是否有必要。我知道 elasticsearch 生成 URL-安全的 Base64 ID's

有人有什么建议吗?我的问题是:

我是一名 Elasticsearch 初学者,但正在寻找最佳实践。我读到在以前的版本中有一个漏洞可以打开远程代码执行。

https://www.elastic.co/blog/scripting-security

http://bouk.co/blog/elasticsearch-rce/

我知道这已解决,但仍想验证 ID。如果 ID 格式不正确,这至少会避免对 Elasticsearch 进行不必要的调用。我所知道的是 "never trust user input" 或者在我的情况下避免可能的输入..

注:我用的是elasticsearch-php客户端

有什么建议吗?谢谢

Should I validate elasticsearch ID ?

如果你愿意。您可以检查是否仅存在字母数字、+/=。这增加了一层额外的安全性,但并非绝对有必要这样做。本着“defence in depth”的精神,我会推荐它。

If no.. is it secure to query the Elasticsearch server directly ? Users will not be able to input the ID, but some [malicious] users can intercept or figure out how to call the Endpoint with a random string, that could be a possible attack or access to a different set of data ?

如果您使用久经考验的 JSON 编码器来构建查询,那么任何攻击者都无法破坏查询并检索他们不想要的数据(即破坏JSON 无法使用串联构建的字符串 - NoSQL Injection 的一种形式)。即使您正在验证我之前描述的 JSON 字符串,也要执行此操作。