captcha_point_load($id) need to validate the $id

Created on 14 May 2025, about 2 months ago

Problem/Motivation

Type php
Date Wednesday, May 14, 2025 - 03:04
User admin
Location https://nkmzs.xyz/node/add
Referrer https://nkmzs.xyz/admin/content
Message TypeError: Cannot access offset of type array on array in Drupal\Core\Entity\EntityStorageBase->load() (line 263 of /home/nkmz/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php).
Severity Error
Hostname 2409:8a56:c51:c680:3dfa:3b70:b8f8:b55
Operations
Backtrace
#0 /home/nkmz/web/modules/contrib/captcha/captcha.module(64): Drupal\Core\Entity\EntityStorageBase->load()
#1 /home/nkmz/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(400): captcha_point_load()
#2 /home/nkmz/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(395): Drupal\Core\Entity\EntityStorageBase->Drupal\Core\Entity\{closure}()

Steps to reproduce

install hcaptcha module ,change existing captcha point to use hcaptcha

Proposed resolution

file:~ captcha.module ,then locate function captcha_point_load($id) and change it as below"~

function captcha_point_load($id) {

if (empty($id) || !is_string($id)) {
  return NULL;
}

  try {
    return CaptchaPoint::load($id);

  }
  catch (\Exception $e) {

    \Drupal::logger('captcha')->error('Failed to load captcha point: @error', ['@error' => $e->getMessage()]);
    return NULL;
  }


}

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.0

Component

Captcha API (captcha)

Created by

🇨🇳China huangweiqiu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024