Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@baloo
Copy link
Contributor

@baloo baloo commented Apr 8, 2013

Considering the following route

GET /foo/:baz controllers.Foo.bar(baz)
object Foo extends Controller {
  def bar(baz: String) = Action {
     Ok(JSON.stringify(baz))
  }
}

Now, let request the controller with content like:

$ curl http://lolcathost:9000/foo/bar:baz

In actual play-master, ''baz'' is not correctly encoded. ''baz'' parameter in ''bar'' action gets null.

In play <= 2.1.1, the string was passed "as-this" and not encoded in any way. This MAY break user's code, as it may receive a null parameter. This will lead to unexpected behaviour if request is miss-formated.

In this pull request I try to fallback to a safer behaviour and not to pass a null parameter to user code.

@julienrf
Copy link
Contributor

julienrf commented Apr 8, 2013

Please take a look at #796, #684, #703 and #976 to avoid duplication and to consider the robustness of your solution.

@cloudbees-pull-request-builder

play2-master-PRs #19 SUCCESS
This pull request looks good

@baloo
Copy link
Contributor Author

baloo commented Apr 8, 2013

For me it just fix the #976 issue.

@jroper
Copy link
Member

jroper commented Apr 9, 2013

This is not the right solution. If the URI is foo:%20bar, the %20 won't be decoded. We don't want to abort all decoding just because one illegal character exists.

The reason this is failing by the way is because the colon is causing the parsing to think that the protocol is foo, and the hostname is bar. Therefore, the path is null. So it seems that new URI(path).getPath is not the right method to use for tolerant path segment decoding. What we need to solve this issue is use a path segment decoder, not something that tries to parse the string we pass in as a URI. I don't know if such a thing exists in Java, maybe we have to write our own.

@jroper
Copy link
Member

jroper commented Apr 9, 2013

So, I actually found the specific part of the URI spec that we are breaking, from section 3.3:

In addition, a URI reference (Section 4.1) may be a relative-path reference, in which case the first path segment cannot contain a colon (":") character.

A path segment by itself is a relative URI reference, and therefore, if the segment contains a ":", and we try to parse it as a URI, we are breaking the spec.

So the simplest solution here I think is turn it into an absolute path, by prepending a /, and then dropping it after decoding.

So the following should work:

new URI("/" + group).getPath.drop(1)

@baloo
Copy link
Contributor Author

baloo commented Apr 9, 2013

Please take a look at those commit, and particularly the last one. The fix you suggest introduces some noise in error reporting

@cloudbees-pull-request-builder

play2-master-PRs #22 SUCCESS
This pull request looks good

@etaty
Copy link
Contributor

etaty commented Apr 9, 2013

Looks bad to me
I like to repeat myself :)
#937 (comment)

Maybe we should work on a implementation, and not a hack on ten other hack ?
#937

huntc added a commit that referenced this pull request Apr 15, 2013
Do not return null if parameter is not correctly encoded
@huntc huntc merged commit 6e36d7e into playframework:master Apr 15, 2013
jroper added a commit that referenced this pull request Apr 15, 2013
Squashed commit of the following:

commit 171b9ad
Author: Arthur Gautier <[email protected]>
Date:   Tue Apr 9 08:06:09 2013 +0200

    Change test to new pattern

commit b4c5219
Author: Arthur Gautier <[email protected]>
Date:   Tue Apr 9 08:05:46 2013 +0200

    Add test for invalid encoded character

commit 8f13cca
Author: Arthur Gautier <[email protected]>
Date:   Tue Apr 9 07:55:10 2013 +0200

    Fix as jroper suggested

commit 63f298c
Author: Arthur Gautier <[email protected]>
Date:   Mon Apr 8 22:37:02 2013 +0200

    Do not return null if param is not correctly encoded

commit 81e48f8
Author: Arthur Gautier <[email protected]>
Date:   Mon Apr 8 21:46:16 2013 +0200

    non-encoded string should not return null
jroper added a commit that referenced this pull request Apr 15, 2013
Squashed commit of the following:

commit 171b9ad
Author: Arthur Gautier <[email protected]>
Date:   Tue Apr 9 08:06:09 2013 +0200

    Change test to new pattern

commit b4c5219
Author: Arthur Gautier <[email protected]>
Date:   Tue Apr 9 08:05:46 2013 +0200

    Add test for invalid encoded character

commit 8f13cca
Author: Arthur Gautier <[email protected]>
Date:   Tue Apr 9 07:55:10 2013 +0200

    Fix as jroper suggested

commit 63f298c
Author: Arthur Gautier <[email protected]>
Date:   Mon Apr 8 22:37:02 2013 +0200

    Do not return null if param is not correctly encoded

commit 81e48f8
Author: Arthur Gautier <[email protected]>
Date:   Mon Apr 8 21:46:16 2013 +0200

    non-encoded string should not return null
@etaty
Copy link
Contributor

etaty commented Apr 15, 2013

LOL

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.

6 participants