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)

Author: raizen10Created Sep 23, 2026Updated Sep 23, 2026

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:

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

  1. 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.
  2. Empty value matches everyone. With no email, the condition becomes LIKE '%%' and returns the first person in the CRM.
  3. 500 on an empty/incomplete payload. In that case request('persons') is null, so array_merge(null, [...]) throws a TypeError and the endpoint returns HTTP 500 instead of a validation error.

Preconditions

  1. Krayin CRM v2.2.6 (same code on the current 2.2 branch).
  2. A web form (Settings → Web Forms) and at least one existing person.

Steps to reproduce

  1. Submit the web form with an email that is a substring of an existing contact's email.
  2. 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.