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

avoid overwriting params with falsey value #1418

Closed
wants to merge 1 commit into from
Closed

Conversation

namusyaka
Copy link
Member

@namusyaka namusyaka commented Apr 15, 2018

This behavior arises from the commit that mustermann was introduced.
see: 7a9ffcc

That breaks backward compatibility with Sinatra v1.4.X and is not intended behavior.
This changes it so that it overwrites params only if there is a possible value as a block argument.

Fixes #1417

I want a cautious review on this PR. After sufficient review, I'm planning to merge the commit.
/cc @rkh @zzak @nickpelone

@namusyaka namusyaka requested review from rkh and zzak April 15, 2018 12:32
This behavior arises from the commit that mustermann was introduced.
see: 7a9ffcc

That breaks backward compatibility with Sinatra v1.4.X and is not intended behavior.
This changes it so that it overwrites params only if there is a possible value as a block argument.

Fixes #1417
@namusyaka
Copy link
Member Author

namusyaka commented Apr 15, 2018

To fix broken tests, applied #1419. Force pushed, but changes are nothing.

@nickpelone
Copy link

👍 thanks again!

@namusyaka
Copy link
Member Author

@nickpelone Thanks for confirming my patch. I'll let @zzak and @rkh review this. Please wait for merging.

@namusyaka namusyaka added this to the v2.0.2 milestone Apr 28, 2018
@rkh
Copy link
Member

rkh commented May 2, 2018

The change looks good for what it wants to do.

But I don't think we want this change, it might be opening up for security issue or at least bugs where someone is assuming a param can only be set via pattern (ie, imagine someone limiting what :id can capture and then relying on that as enough security):

set :pattern, capture: { ext: %w[home imprint] }

get '/:page?' do
  page = params[:page] || 'home'
  path = File.expand_path(page, page_directory)
  send_file path
end

@nickpelone
Copy link

I've never used the feature you describe above - I sanitize my params (wherever they originated in the stack: optional captures, request bodies, etc) with an external gem.

Without getting too in the weeds here, my approach worked in Sinatra 1.4, but is broken in 2.x, where one of the stated desires was for people to file a ticket if their app stopped working. (and for what it's worth, I imagine the situation described above would happen in Sinatra 1.4.x too, re: assuming captures could only come from the route matcher).

I could even live with an option I had to toggle on, but for this behavior to go totally away, forever, would be very depressing to me. (In addition to necessitating a revision of my API I design / deciding to backport to the entire Sinatra 1.x / Rack 1.x ecosystem and live in the past...eww!)

I have strong interest in seeing this functionality restored - so if another approach is needed I could dive into the code and propose one, failing all else.

Thanks.

@namusyaka
Copy link
Member Author

Since received @rkh's comment, I have reconsidered this issue.
As a result, I thought this behavior was certainly undesirable.
This is because even if there are duplicate parameters in path and request body (or query), they should be handled separately.
For example, unlike what is included in the request body, parameters included in path do validation by URI at the previous stage, the request body is not validated.

What I'd like to say is that it is not important that validation is carried out, but the two elements are different in nature.
In other words, the original behavior is wrong, I think.

However, we should look to the fact that this errant behavior was working with traditional sinatra.
For example, we can explicitly write in the document that this behavior has been fixed.

/cc @nickpelone @rkh

In any case, I decided to close this PR as an unwanted change.
Last, @nickpelone Thank you so much for bringing this up.

@namusyaka namusyaka closed this May 5, 2018
@namusyaka namusyaka deleted the fix-1417 branch May 5, 2018 07:32
@nickpelone
Copy link

☹️

@nickpelone
Copy link

Upon further reflection, I figure I can make this "lax" style I was using work with an extra helper method in those route blocks so I guess I'll stop being so grumpy. Thanks for taking a look.

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

Successfully merging this pull request may close these issues.

3 participants