dotnet / WatsonWebserver

Watson is the fastest, easiest way to build scalable RESTful web servers and services in C#.
MIT License
403 stars 83 forks source link

Requesting URL with char "%" in it returns HTTP Error 400. The request URL is invalid. #106

Open ernadhodzic opened 1 year ago

ernadhodzic commented 1 year ago

When URL contains character % in URL request it returns message below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">

Bad Request

Bad Request - Invalid URL


HTTP Error 400. The request URL is invalid.

Is there any workaround to solve this issue ?

jchristn commented 1 year ago

I just tried this using the Test.Default project and cURL (curl http://localhost:8080/foo%bar) and could not reproduce it. Please tell me more about your environment, operating system, runtime, and whether you're trying from localhost or a remote machine.

ernadhodzic commented 1 year ago

foo%bar indeed works. I tried now and its weird that some combinations with % works, some do not. For example combination which does not work is: abc%1b while abc%abc can be accessed. I think encoding also is messing with char % which as of my knowledge should not. Here is screenshot what in debugger is captured when server catches request with % in url request. data1 As of environment, i`m using windows 10; .NET framework 4.7.2; WatsonWebserver 4.3.6.0.

jchristn commented 1 year ago

Ok, I think I see what's happening. The % is used for encoding characters into the URL, and there are only (apparently) specific valid combinations: https://developer.mozilla.org/en-US/docs/Glossary/percent-encoding and https://www.w3schools.com/tags/ref_urlencode.ASP

Are the values that fail for you outside of this supported set?

ernadhodzic commented 1 year ago

Yes, the values which are out of this supported set are failing to find route. Microsoft libraries which can be used for implementing restful api server are handling values which are outside of percent encoding set.