8000 [3.0] [Form] Ensure that the input of basic fields is a string · Issue #4102 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[3.0] [Form] Ensure that the input of basic fields is a string #4102

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

Closed
webmozart opened this issue Apr 24, 2012 · 8 comments
Closed

[3.0] [Form] Ensure that the input of basic fields is a string #4102

webmozart opened this issue Apr 24, 2012 · 8 comments

Comments

@webmozart
Copy link
Contributor

The PR #2421 tries to fix the case where the browser sends an array for a text field. Before this change, the Form framework did not check the data and passed it through to the model layer.

The idea is correct, but the implementation is not. Data fixing is no transformation. Furthermore, the transformer needs to be removed every time someone wants to add a custom transformer.

Thus #2421 should be reverted and replaced by an EnsureStringInputListener, that simply casts the data to string or leaves it null (happens if the field was not submitted). This listener should be connected with the BIND_CLIENT_DATA event of all types that expect a string as input (for example by waiting for #4046 to be merged and adding the listener in FormType if "primitive" is set to true).

@gimler
Copy link
Contributor
gimler commented Jun 9, 2012

i will work on that

@webmozart
Copy link
Contributor Author

I spent some time again today trying to figure out how to do this. Basically, we want to check whether the submitted data matches some given type and either

  • replace it by NULL and proceed, or
  • abort with an exception

This protects the application from arrays being passed to the model through simple types such as "text", which might facilitate exploits.

The submitted data types in core are:

  • array for compound forms and the collapsed single choice form (which is simple)
  • string for simple forms
  • UploadedFile for the file form

We already have a similar facility for checking the type of the view data: The "data_class" option, which lets you configure the expected class.

Extending this option to accept any type (i.e. suffixes of the is_*() functions and class names) would solve the above problem.

Problems:

  • The name "data_class" would be incorrect. "view_data_type" would be better.
  • Already now it is confusing why "data_class" configures the view data type. This is another sign that the name of the option should be changed.
  • BUT: People who don't know about the different data representations wouldn't have any idea what "view_data_type" means (and they need to use it basically everywhere, like "data_class" today)

Unsure what to do.

@webmozart
Copy link
Contributor Author

By the way, a related issue is the "input" option of the date, time and datetime types. This could also better be named "model_data_type" (even though it is not always strictly a data type, like "datetime").

@Tobion
Copy link
Contributor
Tobion commented Aug 25, 2012

Whatever solution you come up with, please don't raise exception that can indirectly be invoked by submitting unexpected data. See #5334.

@webmozart
Copy link
Contributor Author

You are right. So instead of "abort with an exception" the field should be dealt with as if it was empty (i.e. initialized with "empty_data").

@webmozart
Copy link
Contributor Author

ref #7917

@stof
Copy link
Member
stof commented Aug 18, 2014

@webmozart any news about this ?

@nicolas-grekas
Copy link
Member

\o/

nicolas-grekas added a commit that referenced this issue Dec 8, 2018
…kas)

This PR was merged into the 3.4 branch.

Discussion
----------

[Form] Filter arrays out of scalar form types

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

Replaces fix #20935

Commits
-------

000e4aa [Form] Filter arrays out of scalar form types
symfony-splitter pushed a commit to symfony/form that referenced this issue Dec 8, 2018
…kas)

This PR was merged into the 3.4 branch.

Discussion
----------

[Form] Filter arrays out of scalar form types

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#4102
| License       | MIT
| Doc PR        | -

Replaces fix symfony/symfony#20935

Commits
-------

000e4aab5e [Form] Filter arrays out of scalar form types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0