-
-
Notifications
You must be signed in to change notification settings - Fork 432
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
Request validation fails on localhost #118
Comments
From a quick inspection it looks like the error you're not checking is relevant: route, pathParams, _ := oa3router.FindRoute(r.Method, r.URL)
// panic(_) = http: panic serving 127.0.0.1:60896: Does not match any server The invalid route comes from the fact that Turns out that the host part of r.URL.Scheme = "http"
r.URL.Host = r.Host If you happen to know why BTW if you're down these functions could probably do with some polish:
|
Right, that's the issue I was pointing to in the linked StackOverflow thread. My understanding (as a golang neophyte) is that the scheme/host are unset because the HTTP request on localhost is a relative URL, it only includes the path, not the host. Should it treat relative URLs as always matching a server? Should it never match any server and always fail? (This is basically what it's doing now, which seems inconvenient but you could argue is correct behaviour) Require an explicit host header? (and then respect that?) How do other openapi request-validation libraries handle this situation? |
Are we sure that Once the above point proved then yes we should be doing some smarter matching. |
I'll dig into this more later, but according to this
For reference net/http docs say:
|
I’m not sure I checked r.RequestURI. |
@fenollp Is this something you're working on? Otherwise, I think I might look into it myself |
We hacked in a workaround for our local tests, but I'd be happy to see a proper upstream fix. Is there consensus on what the desired behavior should be? My suggestions are:
|
@antonjah I am not working on a fix for this. PRs welcomed :) |
I just found that setting an empty list for the |
I had the same problem and I did the following to address the issue in a more elegant way. Basically updated the URL before invoking FindRoute method. This solution will work in all environments.
Updated my servers in spec to include localhost server.
|
Work on #210 has progressed. Now routers implement |
Hello, I'm not sure if this is a bug strictly-speaking, but we found it to be unexpected behavior.
Say you have a basic spec like this:
And then a simple web app that includes validation using
kin-openapi/openapi3filter
:If you run
$ go run main.go
and make a request using$ curl localhost:8080
you'll find you get aninvalid route
response.The logging output is:
As far as I can tell the issue is the same one described in this StackOverflow thread
Since the request is made from the same machine, it's only passing a relative URL, and
openapi-kin
doesn't know how to validate that request successfully. Even explicitly passing aHost
header doesn't help:Maybe the
FindRoute()
method should take into accountHost
headers? Or maybe there's someplace thatURL.ResolveReference()
should be called and it's not?I'm willing to work on putting together a PR, if there's consensus for what a good fix would look like. Otherwise, I'd just ask for extra documentation that
kin-openapi
validation doesn't work properly onlocalhost
.Thanks for your work on a very useful tool.
The text was updated successfully, but these errors were encountered: