8000 [Form] Moved POST_MAX_SIZE validation from FormValidator to request handler by webmozart · Pull Request #11924 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Moved POST_MAX_SIZE validation from FormValidator to request handler #11924

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

Merged
merged 2 commits into from
Sep 24, 2014

Conversation

webmozart
Copy link
Contributor
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #11729, #11877
License MIT
Doc PR -

array('{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize())
));

// The form stays unsubmitted, since we have no data to submit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks wrong to me. It should be marked as submitted but invalid IMO, as this case means that the client tried to submit it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we submit it as empty form and suppress all other validation to prevent further error messages?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, submitting it as an empty form would make thing more complex in case of an edit form, as it would empty all fields rather than keeping the previous values.
I think we should mark the form as submitted, but without submitting the data for children (it could rely on the partial binding though)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. If we disable the $clearMissing parameter, as in PATCH requests, that should work. I don't really want to add a way for marking a form as submitted, that could be misused quite heavily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm: This means that every form with a matching request method (for example, if there are multiple POST forms on one page) will show the error and report being submitted. Is this desired?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated now.

@stof stof added the Form label Sep 20, 2014
@webmozart
Copy link
Contributor Author

ping @symfony/deciders

@fabpot
Copy link
Member
fabpot commented < 8000 a href="#issuecomment-56505491" id="issuecomment-56505491-permalink" class="Link--secondary js-timestamp">Sep 23, 2014

👍

@@ -53,6 +68,25 @@ public function handleRequest(FormInterface $form, $request = null)
$data = $request->query->get($name);
}
} else {
// Mark the form with an error if the uploaded size was too large
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code block is duplicated. So I guess one could refactor this. E.g. HttpFoundationRequestHandler extends NativeRequestHandler and then overwrites certains methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are a lot of similarities between the two request handlers. On the other hand, there are lots of tiny differences, so we'd end up with a pretty complex class + control flow if we remove all the duplications. Both classes are covered by the same test case, so if tests are added, both classes need to be adapted.

Feel free to try to remove the duplication in a new PR, there we can discuss how to do that well and whether it is really worth it.

@Tobion
Copy link
Contributor
Tobion commented Sep 23, 2014

👍

@Tobion
Copy link
Contributor
Tobion commented Sep 23, 2014

Oh wait, this is for 2.3? So I don't agree to deprecate Form/Extension/Validator/Util/ServerParams in a maintainance branch. Why is that necessary?

@webmozart
Copy link
Contributor Author

@Tobion Good point, thanks! I'll remove the deprecation note.

I moved ServerParams to the global Util namespace since it's not just used for the ValidatorExtension now.

@webmozart
Copy link
Contributor Author

Updated.

@fabpot
Copy link
Member
fabpot commented Sep 24, 2014

Thank you @webmozart.

@fabpot fabpot merged commit 759ae1a into symfony:2.3 Sep 24, 2014
fabpot added a commit that referenced this pull request Sep 24, 2014
…o request handler (rpg600, webmozart)

This PR was merged into the 2.3 branch.

Discussion
----------

[Form] Moved POST_MAX_SIZE validation from FormValidator to request handler

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #11729, #11877
| License       | MIT
| Doc PR        | -

Commits
-------

759ae1a [Form] Moved POST_MAX_SIZE validation from FormValidator to request handler
4780210 [Form] Add a form error if post_max_size has been reached.
fabpot added a commit that referenced this pull request Sep 25, 2014
…ndationExtension for forward compatibility with 2.5 (webmozart)

This PR was merged into the 2.3 branch.

Discussion
----------

[Form] Removed constructor argument from FormTypeHttpFoundationExtension for forward compatibility with 2.5

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This argument was introduced in #11924. No release was made of the 2.3 branch after merging that PR.

Since a different constructor argument (`$requestHandler`) was added to FormTypeHttpFoundationExtension in the 2.5 branch, we cannot merge this forward in a BC fashion. For this reason, I removed the argument again.

Commits
-------

6cbc862 [Form] Removed constructor argument from FormTypeHttpFoundationExtension for forward compatibility with 2.5
@rvanlaak
Copy link
Contributor

I've updated to 2.5.5 and tested this implementation. The MAX_POST_SIZE error is added, but the CSRF-invalid error also gets added. So, it seems this check occurs after the CSRF-check (?).

Errors that are added via an event listener in the FormType do also still occur.

$builder->addEventListener(FormEvents::POST_SET_DATA, array($this, 'isFiletypeValid'));

So it seems FormEvents::POST_SET_DATA is still triggered when the form already has an error. Does the latter event also trigger the CSRF-check?

@craue
Copy link
Contributor
craue commented Sep 30, 2014

I was curious to see that error and also tried triggering it by setting post_max_size = 1M in php.ini and uploading a larger file. But may it be with or without this PR, all I get is a plain PHP warning like Warning: POST Content-Length of 4242283 bytes exceeds the limit of 1048576 bytes in Unknown on line 0 printed on top of the rendered page. So in which case is this error message meant to be shown?

fabpot added a commit that referenced this pull request Apr 12, 2020
…Dude)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[Form] Deprecated unused old `ServerParams` util

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| Deprecations? | yes
| Tickets       | ~
| License       | MIT
| Doc PR        | ~

A left over after #11924 (comment), this class is unused since Symfony 2.3 ^^'. I've noticed it before but never took the time to submit a PR because this is very minor IMHO. But since this deprecation should not impact anyone, let's keep the codebase clean and remove it in 6.0.

Commits
-------

e05e924 [Form] Deprecated unused old `ServerParams` util
symfony-splitter pushed a commit to symfony/form that referenced this pull request Apr 12, 2020
…Dude)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[Form] Deprecated unused old `ServerParams` util

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| Deprecations? | yes
| Tickets       | ~
| License       | MIT
| Doc PR        | ~

A left over after symfony/symfony#11924 (comment), this class is unused since Symfony 2.3 ^^'. I've noticed it before but never took the time to submit a PR because this is very minor IMHO. But since this deprecation should not impact anyone, let's keep the codebase clean and remove it in 6.0.

Commits
-------

e05e924c5a [Form] Deprecated unused old `ServerParams` util
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4AD3
Development

Successfully merging this pull request may close these issues.

7 participants
0