-
Notifications
You must be signed in to change notification settings - Fork 43
Description
Describe the bug
A pentester has hit the wporg-patterns api in such a way that the pattern directory generates an invalid ElasticSearch request. Causing a 400 Bad Request warning.
I can't tell if this is supposed to work, as the code-branch doesn't currently work. I suspect this is just unexpected input to the API endpoint.
For example:
GET patterns/wp-json/wp/v2/wporg-pattern?per_page=6&curation=core&search=block
This code:
pattern-directory/public_html/wp-content/plugins/pattern-directory/includes/search.php
Lines 152 to 154 in f7ffec0
| $filter['bool']['must'][] = [ | |
| 'terms' => [ "taxonomy.$taxonomy.term_id" => $term['terms'] ], | |
| ]; |
resulted in this ES query, and response:
Query piece: {"terms":{"taxonomy.wporg-pattern-keyword.term_id":"core"}}
Error: [terms] query does not support [taxonomy.wporg-pattern-keyword.term_id]
terms valid input would be an array, and well core is never going to match a term_id.. which is what leads me to think that the endpoint is not expecting a query-by-slugs.
To Reproduce
Steps to reproduce the behavior:
- Query via patterns/wp-json/wp/v2/wporg-pattern?per_page=6&curation=core&search=block
- Get a 400 error.
- To get the underlying ES error, you need to be an automattician with a WordPress.com sandbox so you can get the underlying queries.
Expected behavior
Either the API should throw a error immediately if it gets invalid input OR the fields should be validated prior to querying ES.
E_USER_WARNING: jetpack_search_abort - no_search_results_array - {"errors":{"invalid_search_api_response":["Invalid response from API - 400"]},"error_data":[]} in wp-content/plugins/pattern-directory/includes/search.php:186