Problem/Motivation
The CAPTCHA module's captcha_sessions table has a sid column that is meant to contain the user's session ID (if present). Drupal core's (since 7.x) session ID column has a length of 128 characters, but captcha_sessions.sid is limited to 64; this makes it possible for a logged in user to run into fatal errors when CAPTCHA attempts to insert their up-to-128-char SID into the captcha_sessions table (such as #3151110: Fatal Error: Captcha session_id too long ).
I stumbled into this issue recently, getting the fatal error Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'sid' at row 1: INSERT INTO "captcha_sessions" ("uid", "sid", "ip_address", "timestamp", "form_id", "solution", "status", "attempts") when loading a Webform in Drupal 11.3 with CAPTCHA 2.0.10.
Fixing the table locally solved my issue:
ALTER TABLE captcha_sessions MODIFY sid VARCHAR(128) NOT NULL DEFAULT '';
Steps to reproduce
- Log in with a session ID larger than 64 characters (e.g. with session hash function sha512 or
session.sid_length=128) - Attempt to access a Webform protected by CAPTCHA
Proposed resolution
Bump the captcha_sessions.sid column length to 128 characters.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
Column captcha_sessions.sid altered to VARCHAR(128).
Issue fork captcha-3631101
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jay.dansand commentedComment #4
jay.dansand commentedComment #6
japerryDrupal core does not generate session IDs itself: PHP does, and `session.sid_length` can be anything up to 256. So a site with a long session ID configured hits "1406 Data too long for column 'sid'" on MySQL.
Widening the column to 128 (as in the first commit on MR !144) would not cover a 256-character ID. Core's own `sessions.sid` is 128 wide, but it never stores the raw ID: SessionHandler writes `Crypt::hashBase64($sessionId)`, a fixed 43 characters. That is the approach I've taken here:
Comment #7
japerry