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

When I have :/ it fails to make the mapping #308

Closed
ggeorgiev opened this issue Jan 26, 2017 · 12 comments
Closed

When I have :/ it fails to make the mapping #308

ggeorgiev opened this issue Jan 26, 2017 · 12 comments
Labels

Comments

@ggeorgiev
Copy link

When I have a string variable in the url that contains :/ (escaped as %3A%2F) the mapping fails with error Not Found

@tmc
Copy link
Collaborator

tmc commented Jan 26, 2017

@ggeorgiev hi there, thanks for your issue report -- could you please put this sort of failing scenario into a test case?

@ggeorgiev
Copy link
Author

@tmc Hi, I will try to find some time to do so. Considering that I am not familiar with the code base and the usual bootstrap overhead it might take some time. Meanwhile, someone that is working on the project probably will have success to reproduce the issue considering that there is nothing tricky for the scenario to expose it and it is 100% reproducible.

@ggeorgiev
Copy link
Author

I did not find where to add such test, but this code seem suspicious because it seems to analyses system characters over already decoded version of the path.

 func (s *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	path := r.URL.Path
	if !strings.HasPrefix(path, "/") {
		OtherErrorHandler(w, r, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
		return
	}

	components := strings.Split(path[1:], "/")
	l := len(components)
	var verb string
	if idx := strings.LastIndex(components[l-1], ":"); idx == 0 {
		OtherErrorHandler(w, r, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	} else if idx > 0 {
		c := components[l-1]
		components[l-1], verb = c[:idx], c[idx+1:]
	}

@ggeorgiev
Copy link
Author

ggeorgiev commented Jan 26, 2017

This is a comment in the URL package:
// Note that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/.
// A consequence is that it is impossible to tell which slashes in the Path were
// slashes in the raw URL and which were %2f. This distinction is rarely important,
// but when it is, code must not use Path directly.

I replaced in the quoted before code path := r.URL.Path with path := r.URL.RawPath and the not found problem got solved. Of course, the components, need to get decoded after the split in order this to works as before.

@ggeorgiev
Copy link
Author

ggeorgiev commented Jan 26, 2017

The problem actually is way more serious from what I noticed initially. Essentially any value in the path that includes '/' will completely mess up the components.

@ggeorgiev
Copy link
Author

ping - is someone looking at this? Seems like a serious issue.

@tmc
Copy link
Collaborator

tmc commented Feb 16, 2017

@ggeorgiev you can simply capture those parameters in either get params or in the body for now. If you can submit a failing test case it will lower the barrier to fixing this.

@jessesuen
Copy link

We were also hit by this issue. I submitted PR #660 which allows encoded slashes as part of a path.

@stale
Copy link

stale bot commented Sep 9, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 9, 2019
@stale stale bot closed this as completed Sep 16, 2019
@kindermoumoute
Copy link

This bug still happens with grpc-gateway v1.14.4

@johanbrandhorst
Copy link
Collaborator

Hi, thanks for the bump. I'll repopen. Would you be interested in submitting a fix?

@stale stale bot removed the wontfix label Apr 9, 2020
@stale
Copy link

stale bot commented Jun 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 8, 2020
@stale stale bot closed this as completed Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants