Web form submission: person lookup uses a partial `LIKE` match on email, so leads get attached to unrelated contacts (and an empty submission returns 500)
Bug report
Title
Web form submission: person lookup uses a partial LIKE match on email, so leads get attached to unrelated contacts (and an empty submission returns 500)
Issue Description
WebFormController::formStore() (packages/Webkul/WebForm/src/Http/Controllers/WebFormController.php, branch 2.2, ~line 51) looks up an existing person like this:
$person = $this->personRepository
->getModel()
->where('emails', 'like', '%'.request('persons.emails.0.value').'%')
->first();
if ($person) {
request()->request->add(['persons' => array_merge(request('persons'), ['id' => $person->id])]);
}Problems:
- Partial match.
LIKE '%value%'matches substrings, so a submission with e.g.[email protected]is attached to an existing contact[email protected], and any fragment (a domain such as@gmail.com) matches the first contact that contains it. Since this endpoint is public by design (web forms are embedded on external sites), anyone can create leads linked to existing contacts they don't know. - Empty value matches everyone. With no email, the condition becomes
LIKE '%%'and returns the first person in the CRM. - 500 on an empty/incomplete payload. In that case
request('persons')isnull, soarray_merge(null, [...])throws aTypeErrorand the endpoint returns HTTP 500 instead of a validation error.
Preconditions
- Krayin CRM v2.2.6 (same code on the current
2.2branch). - A web form (Settings → Web Forms) and at least one existing person.
Steps to reproduce
- Submit the web form with an email that is a substring of an existing contact's email.
- Check the created lead's person.
Expected result
A new person is created (or the existing one is reused only on an exact, case-insensitive email match). An empty/invalid payload returns a 422 validation error.
Actual result
The lead is attached to the unrelated existing contact. An empty POST to /web-forms/forms/{id} returns 500.
Suggested fix
Validate the payload first (persons.emails.0.value required|email), then match exactly, e.g. with JSON_CONTAINS(emails, JSON_OBJECT('value', ?)) or by filtering candidates in PHP with a case-insensitive === comparison of each stored email value.
Source: krayin/laravel-crm