Repository navigation
login/login: guard post fields in validate() - #502
Merged
Merged
Conversation
validate() reads $this->request->post['username'] and ['captcha'] without checking whether the keys exist. A POST request dispatched to this controller without the login form produces on PHP 8: Warning: Undefined array key "username" strlen(null) is also deprecated since PHP 8.1, so line 131 warns twice on newer versions. Treating a missing field as empty keeps the existing behaviour - validation fails either way. The reads at lines 48, 51 and 95 are left alone: they run only after validate() has returned true, so the key is guaranteed to exist.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ControllerLoginLogin::validate()reads two POST fields without checkingwhether the keys exist:
Any POST request dispatched to this controller without the login form produces
on PHP 8:
strlen(null)is also deprecated since PHP 8.1, so line 131 warns twice onnewer versions.
Treating a missing field as empty keeps the existing behaviour - validation
fails with
text_invalid_usernameeither way.The reads at lines 48, 51 and 95 are left alone: they only run after
validate()has returned true, so the key is guaranteed to exist.Verified on a live 1.4.9 install: the warning is gone from the PHP-FPM log for
a POST without form fields, and normal login as well as the empty-username
validation error behave as before.
Environment: piler 1.4.9, PHP 8.5, Ubuntu 26.04, nginx.