0

I have an application that uses Javascript code to generate URLs that are sent to a REST endpoint running under Apache Tomcat 8.5. The data sent to the URL includes an identifier field that may contain "special" characters. I encode this identifier using the Javascript function encodeURIComponent.

However, with some of the identifier strings, the connection is being instantly terminated after the URL is sent (without even waiting for the request to be fully sent), with the error 400 Bad Request and an empty response entity.

An example URL that causes the failure is:

 http://localhost:3000/admin_api/getTranscript/%2B~%2B)%2Fe*3%3Ep%2596%5B(%2Fv%3C03

This doesn't appear to be related to this similar question because the characters causing issue in that particular case are |, { and }, none of which are present in my URL.

Why is Tomcat rejecting this URL, and what can I do to prevent this issue? I'd prefer a change on the server side rather than client, because I have already-deployed clients that would need updating.

Jules
  • 14,841
  • 9
  • 83
  • 130
  • Unless I am much mistaken, `(` and `)` are not legal components of a URL, so there is something wrong with your encoding process. – user207421 Feb 27 '18 at 09:18
  • @EJP - I'm using the standard javascript `encodeURIComponent` function, which is explicitly designed for this purpose. It seems to me that `(` and `)` *are* valid URL characters -- they're defined in RFC3986 as part of the `sub-delims` set. The path component of a URL is then defined as `path = path-abempty / [others]`, `path-abempty = *( "/" segment )`, `segment = *pchar`, and finally `pchar = unreserved / pct-encoded / sub-delims / ":" / "@"`, so I don't see a problem with the URL here. – Jules Feb 27 '18 at 09:27
  • Ah -- found another question & answer that does seem to match my problem: https://stackoverflow.com/questions/36220740/why-is-this-url-returning-error-400-from-tomcat – Jules Feb 27 '18 at 09:34

0 Answers0