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

not handling escaped forward slashes properly #208

Open
tmornini opened this issue Jul 26, 2017 · 1 comment
Open

not handling escaped forward slashes properly #208

tmornini opened this issue Jul 26, 2017 · 1 comment

Comments

@tmornini
Copy link

Hey there. Just found this issue:

package main

import (
	"net/http"

	"github.com/julienschmidt/httprouter"
)

func main() {
	router := httprouter.New()

	router.GET(
		"/networks/:network-id/accounts/:network-account-id/purchases/:purchase-id",
		getPurchaseHTTPRouter,
	)

	panic(http.ListenAndServe(":8080", router))
}

func getPurchaseHTTPRouter(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
	w.WriteHeader(200)
	w.Write([]byte("routed\n"))
}

Without an encoded forward slash, this works correctly:

$ curl localhost:8080/networks/1/accounts/2/purchases/3
routed

But with an encoded forward slash, it does not.

$ curl localhost:8080/networks/1/accounts/2/purchases/3%2F4
404 page not found

I'm quite confident that the second example should have routed and the purchase-id parameters should be set to "3/4"

@RazerM
Copy link

RazerM commented May 17, 2019

ORY Hydra had an API where you accept a parameter like /login?login_challenge={challenge}, and then you call Hydra's API with /oauth2/auth/requests/login/{challenge}. They recently changed to use query parameters so the API caller doesn't have to escape the challenge (ory/hydra#1307).

The linked issue says "if [the] challenge is not properly escaped", but that's not true because it uses httprouter! Calling /oauth2/auth/requests/login/..%2F..%2F..%2F..%2Fclients (which is properly escaped) would change the Hydra request path.

I don't use httprouter directly, but when Hydra announced the change and I checked that even with escaping it doesn't work I was quite surprised.

RFC 3986: "When to Encode or Decode":

When a URI is dereferenced, the components and subcomponents
significant to the scheme-specific dereferencing process (if any)
must be parsed and separated before the percent-encoded octets within
those components can be safely decoded, as otherwise the data may be
mistaken for component delimiters.

similark pushed a commit to similarweb/httprouter that referenced this issue May 9, 2023
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](onsi/gomega@v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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

No branches or pull requests

2 participants