2016-04-26 85 views
0

我有一個人正在繞過sql注入的探測,這很好,但我發現彈性搜索拋出錯誤,我認爲這個庫會處理。彈性搜索拋出客戶端客戶端搜索錯誤響應

例如,如果有人做了

' or 1=1 ' -- 

搜索,然後我得到

exception 'Guzzle\Http\Exception\ClientErrorResponseException' with message 'Client error response 
[status code] 400 
[reason phrase] Bad Request 
[url] http://localhost:9200/items/product/_search' in /.../vendor/guzzle/guzzle/src/Guzzle/Http/Exception/BadResponseException.php:43 

如果我們看一下這是做搜索的代碼,我們有

$client = new Client(); 
    $products = $client->search([ 
     'index' => 'product', 
     'type' => 'product', 
     'body' => [ 
      'query' => [ 
       'query_string' => [ 
        'query' => $query, 
       ] 
      ] 
     ] 
    ]); 

哪裏$查詢等於' or 1=1 ' --

那麼,怎麼來的查詢不會逃脫,爲什麼它會拋出一個錯誤,我該怎麼做才能阻止它?我也讓人們試圖通過搜索嘗試執行一些腳本或其他東西。

我不需要花哨的選項(如FOO -bar)

運行elasticsearch/elasticsearch V1.1.0 PHP庫 在服務器上運行elasticsearch V1.7.1

回答

0

嘗試

$client = ClientBuilder::create()->build(); 
+0

ClientBuilder類在哪裏? – Wizzard

+0

你在使用elasicsearch-php嗎? https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_index_management_operations.html –