passbolt/passbolt_api · error · CakeException

" " is not a valid search filter.

Error message

"{0}" is not a valid search filter.

What it means

Thrown by validateFilterSearch when a search filter entry has a non-integer array key. The search filter expects a numerically indexed list of keywords; keys like 'keywords' or '0x' indicate malformed structure.

Solutions

  1. Send search keywords as a numerically indexed list: filter[search][0]=john&filter[search][1]=doe
  2. Server-side, call array_values($values) to reindex before validating if input shape is trusted
  3. Use the correct single-value filter validator if a named filter was intended
  4. Catch CakeException and return 400 describing the expected list format

Example fix

// before
validateFilterSearch(['keyword' => 'john']);
// after
validateFilterSearch(array_values(['keyword' => 'john'])); // ['john']
Defensive patterns

Strategy: validation

Validate before calling

$isShaped = array_is_list($values); if (!$isShaped) { /* reindex or reject */ }

Type guard

$isValid = is_array($values) && array_is_list($values);

Try / catch

try { validateFilterSearch($values); } catch (\Cake\Core\Exception\CakeException $e) { throw new BadRequestException($e->getMessage()); }

Prevention

When it happens

Trigger: Passing an array with string keys to validateFilterSearch, e.g. ['keywords' => 'john'] instead of ['john'], typically from badly parsed query-string filter[search] input.

Common situations: Clients building filter[search][keyword]=x instead of filter[search][0]=x; framework query parsing turning numeric keys into associative ones; hand-constructed arrays in tests.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17). Data as JSON: /api/errors/33d65c25a4026a37. Report an issue: GitHub.

Appendix: source

Thrown at src/Controller/Component/QueryStringComponent.php:448

        return true;
    }

    /**
     * Validate Search Filters
     * Input must be a non-assoc array with utf8 char values between 3 and 64 char in length
     * Example:
     * - Bueno: [0 => 'ada', 1 => 'betty']
     * - No Bueno: ['this' => 'no']
     *
     * @param array $values query items
     * @throw CakeException if the filter is not valid
     * @return bool true if the filter is valid
     */
    public static function validateFilterSearch(array $values): bool
    {
        foreach ($values as $i => $keyword) {
            if (!is_int($i)) {
                throw new CakeException(__('"{0}" is not a valid search filter.', $i));
            }
            if (!is_scalar($keyword) || empty($keyword)) {
                throw new CakeException(__('"{0}" is not a valid search filter.', $i));
            }
            if (!Validation::utf8($keyword)) {
                $msg = __('"{0}" is not a valid search filter. It is not a UTF8 string.', $keyword);
                throw new CakeException($msg);
            }
            if (!Validation::lengthBetween($keyword, 1, 64)) {
                $msg = __('"{0}" is not a valid search filter.', $keyword) . ' ';
                $msg .= __('It should be between 1 and 64 char in length.');
                throw new CakeException($msg);
            }
        }

        return true;
    }

View on GitHub (pinned to 31c1bbc10f)