Skip to content

Search: Invalid ElasticSearch request on pentester submissions #688

@dd32

Description

@dd32

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:

$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:

  1. Query via patterns/wp-json/wp/v2/wporg-pattern?per_page=6&curation=core&search=block
  2. Get a 400 error.
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions