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

Bug: Validation::withRequest() method does not receive data. #4552

Closed
iRedds opened this issue Apr 11, 2021 · 0 comments · Fixed by #4571
Closed

Bug: Validation::withRequest() method does not receive data. #4552

iRedds opened this issue Apr 11, 2021 · 0 comments · Fixed by #4571
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@iRedds
Copy link
Collaborator

iRedds commented Apr 11, 2021

Describe the bug
https://forum.codeigniter.com/thread-79028.html
If method spoofing is used in the html form, then the validation class cannot receive data when using Validation::withRequest() if the enctype="multipart/form-data" attribute was set.

If the method is defined as put, patch or delete, then the validation class tries to get data from the request body (php://input). But if multipart/form-data is used then php://input will be empty.
https://www.php.net/manual/en/wrappers.php.php#wrappers.php.input

CodeIgniter 4 version
4.1.1 and develop

Affected module(s)
Validation class

Expected behavior, and steps to reproduce if appropriate
Expected behavior: When using encoding and multipart/form-data and method spoofing, do not use reading from php://input

Bug reproduction:

// Route
$routes->add('/', 'Home::index');

// controller method 
if ($this->request->getMethod() !== 'get') {
    $rules = ['test' => 'required'];
    if (! $this->validate($rules)) {
       dd($this->validator->getErrors(), $this->request->getVar());
    }
} else {
    echo '<form action="/" method="post" enctype="multipart/form-data">
    <input type="hidden" name="_method" value="put">
    <input type="text" name="test" value="passed">
    <input type="submit">
    </form>';
}

Context

  • OS: Windows 7
  • Web server PHP
  • PHP version 7.3
@iRedds iRedds added the bug Verified issues on the current code behavior or pull requests that will fix them label Apr 11, 2021
@samsonasik samsonasik linked a pull request Apr 15, 2021 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant