Skip to content

[zend-captcha] fix TypeError on array input in Zend_Captcha_Word::isValid() - #239

Open
falkenhawk wants to merge 1 commit into
masterfrom
fix-captcha-word-input
Open

falkenhawk wants to merge 1 commit into
masterfrom
fix-captcha-word-input

Conversation

@falkenhawk

@falkenhawk falkenhawk commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

1) Array input

A tampered request like captcha[input][]=x sends an array instead of the typed word.
Zend_Captcha_Word::isValid() passes it to strtolower(), which throws a TypeError on php 8, so the request ends with a 500 error. php 7 only warned.
An array in captcha[id][]=x ends up in the session namespace name as Array, with an "Array to string conversion" warning.

Both now fail validation with the badCaptcha error, the same result php 7 ended up with after the warning.
Only arrays are rejected, all other values are handled as before.

2) php 8.5: captcha without a name

A captcha used without Zend_Form_Element_Captcha has no name, so isValid() looks up $value[null], which php 8.5 deprecated:

Deprecated: Using null as an array offset is deprecated, use an empty string instead

$captcha = new Zend_Captcha_Figlet();
$id = $captcha->generate();
$captcha->isValid(array('id' => $id, 'input' => $captcha->getWord())); // deprecation on php 8.5

The name is now cast to a string. A null key has always meant '', so the lookup itself does not change.

Other forks

mobtitude/zendframework1#9 casts the input to a string.
That avoids the TypeError, but an array input then becomes the word Array with a warning, and the id and the missing name are not handled.

Ported from a private repository, based on work by @marcing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant