Skip to content

[Form][Validation] Add forbid_extra_data option #7229

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
wants to merge 2 commits into from
Closed

[Form][Validation] Add forbid_extra_data option #7229

wants to merge 2 commits into from

Conversation

marcospassos
Copy link

Fixed indentation.

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #7209
License MIT

Added ignore_extra_data option to allow form validation pass, even with extra data.

@@ -85,6 +85,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'cascade_validation' => false,
'invalid_message' => 'This value is not valid.',
'invalid_message_parameters' => array(),
'ignore_extra_data' => false,
Copy link
Member

Choose a reason for hiding this comment

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

This is misleading IMO. The extra data is always ignored when binding the form (it cannot be bound as there is no field for them). Thus option controls whether it is allowed to send extra data, not whether the form ignores it.

Copy link
Author

Choose a reason for hiding this comment

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

I agree. How about allow_send_extra_data?

Copy link

Choose a reason for hiding this comment

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

I still prefer the name Marco suggested. Technically the form doesn't ignore metadata if it would ignore it then it wouldn't throw an exception.

Copy link
Author

Choose a reason for hiding this comment

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

I think allow_send_extra_data is more clear, but is too verbose (~20% longer).

$factory->create('form.name', new Model(), ['allow_send_extra_data' => true]);

VS

$factory->create('form.name', new Model(), ['ignore_extra_data' => true]);

Copy link

Choose a reason for hiding this comment

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

What about allow_extra_data which would default to false. However I still prefer ignore...

Copy link
Author

Choose a reason for hiding this comment

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

@mvrhov I had thought in this name, but in fact we're not allowing extra data (it does not have any usefulness), we're signaling whether the form should add a violation or not. So, ignore_extra_data brings me to the real goal of this option (if the extra data is ignored, then it must be ignored during validation).

Copy link
Member

Choose a reason for hiding this comment

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

@marcospassos But the name is confusing IMO, because you don't know that this option is related to the validation when you see the configuration of a form.

Copy link
Author

Choose a reason for hiding this comment

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

How about extra_data_violation (default true)?

Copy link
Member

Choose a reason for hiding this comment

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

Another solution could be forbid_extra_data (defaulting to true)

Copy link
Author

Choose a reason for hiding this comment

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

@stof Sounds good for me! 👍

@mvrhov
Copy link

mvrhov commented Mar 1, 2013

a big 👍 for this one as this will also greatly simply bounding the form from query parameters.

@vicb
Copy link
Contributor

vicb commented Mar 1, 2013

a big 👍 for this one as this will also greatly simply bounding the form from query parameters.

Yep but there is also a big implication on security (see what happened to Ruby / GH a few months ago)

@stof
Copy link
Member

stof commented Mar 1, 2013

@vicb This PR does not introduce a security issue for the extra params AFAIK. These extra params won't be bound to the underlying object. They will simply be ignored silently instead of marking the form as invalid.

@marcospassos
Copy link
Author

Really? Can you give me an example?

As far as I know, the issue was something like this:

id = 123 #(target's project id)
project['name'] = 'Title'
project['project_id'] = 321 #(hacker id)

# After execution that POST we got hacker owning target's project.
Project.find(params[:id]).update_attributes(params[:project]) 

You can't reproduce this kind of attack in SF2.

@mvrhov
Copy link

mvrhov commented Mar 1, 2013

Like stof said. The issue in ruby was different. The form automatically bind everything that matched. The Form component in symfony requires a form field with correct property path for something to be bound.

@marcospassos
Copy link
Author

Renamed.

@vicb
Copy link
Contributor

vicb commented Mar 1, 2013

You are right, I was wrong.

Christophe Coevoet notifications@github.com wrote:

@vicb This PR does not introduce a security issue for the extra params
AFAIK. These extra params won't be bound to the underlying object. They
will simply be ignored silently instead of marking the form as invalid.


Reply to this email directly or view it on GitHub:
#7229 (comment)

@marcospassos
Copy link
Author

ping @fabpot

@webmozart
Copy link
Contributor

ref #1341

@webmozart
Copy link
Contributor

Thank you for the PR @marcospassos! We already discussed this issue a lot in #5576 and came to a conclusion about the API, but no-one implemented it yet. Do you have time to adapt your implementation?

@marcospassos
Copy link
Author

@bschussek Let me see if I've got. Instead of setting as option at form creation, it should be passed as second argument of bind method, right?

@webmozart
Copy link
Contributor

Exactly :) The implementation in #5576 was already quite good, just the API was wrong.

@webmozart
Copy link
Contributor

Since this PR is not really related to #1341, I will close it. If you decide to implement #1341, please open a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants