Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: use validateData() instead of validate() in Validation #8331

Merged
merged 1 commit into from
Dec 14, 2023

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Dec 14, 2023

Description

  • validate() is not recommended

Checklist:

  • Securely signed commits
  • [] Component(s) with PHPDoc blocks, only if necessary or adds value
  • [] Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added the documentation Pull requests for documentation only label Dec 14, 2023
@lonnieezell
Copy link
Member

lonnieezell commented Dec 14, 2023

Can you remind me what the differences are between validate() and validateData() here and why we should use the newer one?

Edit: I was able to steal a moment and look at the code. Seems fine, though there's nothing inherently wrong with validate() that I can see either, and it's slightly more usable.

@michalsn
Copy link
Member

The problem with the validate() method is that we have no control over where the data comes from, this issue is related to getVar(), see: https://codeigniter.com/user_guide/incoming/incomingrequest.html#getting-data

The getVar() method will pull from $_REQUEST, so will return any data from $_GET, $POST, or $_COOKIE (depending on php.ini request-order).

So the data from the POST can be replaced by the data from the COOKIE. This issue is no longer so bad since the day the getValidated() method was introduced, which will return the exact values that have been validated.

For developers who do not use getValidated() method to retrieve input data after validation, it may be a security issue which allows to bypass the validation.

With validateData() It is the developer's responsibility to determine where the validation data should come from.

@lonnieezell
Copy link
Member

Ah, that makes more sense to me now. Thanks!

@kenjis kenjis merged commit ad0fb2c into codeigniter4:develop Dec 14, 2023
7 checks passed
@kenjis kenjis deleted the docs-update-valiation-sample branch December 14, 2023 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Pull requests for documentation only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants