I have a JavaScript widget which communicates with my Rails app by creating tags in the DOM. Every once in a while, I see a malformed request in my server logs, where the URL is truncated at 255 characters:
http://myapplication.example/mycontroller/1/myaction?hostname=www.mycustomer.example&request[param_a]=3&request[param_b]=1&request[param_c]=0&request[param_d]=0&request[param_e]=3&request[param_f]=1&request[param_g]=4&request[param_h]=0&request[param_i]=5&request
From Google and Stackoverflow (What is the maximum length of a URL in different browsers?), it looks like 255 characters is not a valid limit on URLs.
Here’s what I know:
- This is a sporadic problem, it does not happen on ALL requests
- URL is truncated at 255 characters when this happens
- When this error happens, the user-agent is not recorded in the backtrace
Here’s what I do NOT know:
- What types of browsers does this error occur on? Perhaps some mobile browser…
What’s the best way to root cause this problem?
The best way to solve the Root Cause is to not make it a GET but a POST Request.
There is AFAIK no set limits on the length of a QueryString, so the real limit is all over the place. I know that 4000 is a limit on some web servers (can’t remember if it was IIS or Apache and if it could be changed), but it is very possible that some browsers have much smaller limits. The fact that you don’t get a user-agent could emphasize that it’s a mobile browser, crawler or other application rather than a real browser.
POST requests are a bit more complex to do, but they can carry much bigger “payloads” and can be configured on the server side.