How to proceed with "Illegal request, responding with status '400 Bad Request'"

2,259 views
Skip to first unread message

Igor Nemilentsev

unread,
Sep 20, 2013, 1:25:22 PM9/20/13
to spray...@googlegroups.com

Hello everyone. I am pretty new in spray and have a question.

Sometimes I am getting errors like this:

[spray.can.server.HttpServerConnection] -
Illegal request, responding with status '400 Bad Request': Illegal request-target, unexpected character '=' at position 96:
/__adutm.gif?adv=20130915&adbn=Chrome&adbv=25.0.1364.172&adsr=http://yandex.ru/clck/jsredir?from=yandex.ru;yandsearch;web;;&text=
                                                                                                                                                           ^
The request is sent by javascript, it use encodeURIComponent but something goes wrong.

Is it possible to process similar requests but do not throw 400 error. I mean some additional logging where I could see whole request or something like this.
Is it possible to get some raw request in this case and process some way?

I use next route:

  val myRoute = {
    get {
      path("__adutm.gif") {
        parameterMap {
          queryParams => { ctx =>
            val url: String = ctx.request.uri.toString()
            worker ! (queryParams, url)
            ctx.complete("")
          }
        }
      }
    }
  }

Johannes Rudolph

unread,
Sep 22, 2013, 3:15:24 AM9/22/13
to spray...@googlegroups.com
Hi Igor,

On Fri, Sep 20, 2013 at 7:25 PM, Igor Nemilentsev <tre...@gmail.com> wrote:
> [spray.can.server.HttpServerConnection] -
> Illegal request, responding with status '400 Bad Request': Illegal
> request-target, unexpected character '=' at position 96:
> /__adutm.gif?adv=20130915&adbn=Chrome&adbv=25.0.1364.172&adsr=http://yandex.ru/clck/jsredir?from=yandex.ru;yandsearch;web;;&text=

that doesn't look like a valid query. See [1] about which characters
are not allowed in a valid query.

That said, you can control the strictness of spray's URL parsing with the

spray.can.server.parsing.uri-parsing-mode

setting. See [2]


[1] http://tools.ietf.org/html/rfc3986
[2] http://spray.io/documentation/1.1-SNAPSHOT/spray-can/configuration/.

--
Johannes

-----------------------------------------------
Johannes Rudolph
http://virtual-void.net
Message has been deleted

Igor Nemilentsev

unread,
Sep 22, 2013, 3:03:05 PM9/22/13
to spray...@googlegroups.com, johannes...@googlemail.com
Hello Johannes.
I see that it is not valid query. But I cannot control client and I want to process the request some way even with non-valid query.
I also use spray.can.server.parsing.uri-parsing-mode = relaxed but it does not help, the error is thrown in this case too.

Martin Grigorov

unread,
Sep 22, 2013, 4:23:26 PM9/22/13
to spray...@googlegroups.com, johannes...@googlemail.com
Hi Igor,


On Sun, Sep 22, 2013 at 9:03 PM, Igor Nemilentsev <tre...@gmail.com> wrote:
Hello Johannes.
I see that it is not valid query. But I cannot control client and I want to process the request some way even with non-valid query.
I also use spray.can.server.parsing.uri-parsing-mode = relaxed but it does not help, the error is thrown in this case too.

Hi Igor,

On Fri, Sep 20, 2013 at 7:25 PM, Igor Nemilentsev <tre...@gmail.com> wrote:
> [spray.can.server.HttpServerConnection] -
> Illegal request, responding with status '400 Bad Request': Illegal
> request-target, unexpected character '=' at position 96:
> /__adutm.gif?adv=20130915&adbn=Chrome&adbv=25.0.1364.172&adsr=http://yandex.ru/clck/jsredir?from=yandex.ru;yandsearch;web;;&text=

The value of adsr parameter must be url encoded.
The best way you can process this request is by returning some error to the client, e.g. 400 Bad Request. Doing anything else would be wrong and will lead to more problems later.

How any parser can realize that 'text' parameter (at the very end of the uri) is part of the adsr's value and not a query string parameter to __adutm.gif ? Since the value of adsr is not url encoded the parser cannot make such assumptions.
 

that doesn't look like a valid query. See [1] about which characters
are not allowed in a valid query.

That said, you can control the strictness of spray's URL parsing with the

spray.can.server.parsing.uri-parsing-mode

setting. See [2]

--
You received this message because you are subscribed to the Google Groups "spray-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spray-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Igor Nemilentsev

unread,
Sep 23, 2013, 1:30:02 PM9/23/13
to spray...@googlegroups.com, johannes...@googlemail.com

Hi Martin,

Hi Igor,

On Sun, Sep 22, 2013 at 9:03 PM, Igor Nemilentsev <tre...@gmail.com> wrote:
Hello Johannes.
I see that it is not valid query. But I cannot control client and I want to process the request some way even with non-valid query.
I also use spray.can.server.parsing.uri-parsing-mode = relaxed but it does not help, the error is thrown in this case too.

Hi Igor,

On Fri, Sep 20, 2013 at 7:25 PM, Igor Nemilentsev <tre...@gmail.com> wrote:
> [spray.can.server.HttpServerConnection] -
> Illegal request, responding with status '400 Bad Request': Illegal
> request-target, unexpected character '=' at position 96:
> /__adutm.gif?adv=20130915&adbn=Chrome&adbv=25.0.1364.172&adsr=http://yandex.ru/clck/jsredir?from=yandex.ru;yandsearch;web;;&text=

The value of adsr parameter must be url encoded.
The best way you can process this request is by returning some error to the client, e.g. 400 Bad Request. Doing anything else would be wrong and will lead to more problems later.

How any parser can realize that 'text' parameter (at the very end of the uri) is part of the adsr's value and not a query string parameter to __adutm.gif ? Since the value of adsr is not url encoded the parser cannot make such assumptions.

Thanks for the clarification. What I mostly supposed to find it is some hook before the error 400 is thrown,  where I could process even wrong request and allow the error be thrown.

 

Johannes Rudolph

unread,
Sep 24, 2013, 4:53:55 AM9/24/13
to Igor Nemilentsev, spray...@googlegroups.com
Hi Igor,

On Mon, Sep 23, 2013 at 7:30 PM, Igor Nemilentsev <tre...@gmail.com> wrote:
>>> Hello Johannes.
>>> I see that it is not valid query. But I cannot control client and I want
>>> to process the request some way even with non-valid query.
>>> I also use spray.can.server.parsing.uri-parsing-mode = relaxed but it
>>> does not help, the error is thrown in this case too.

Try `spray.can.server.parsing.uri-parsing-mode =
relaxed-with-raw-query`. That should give you the query part of the
URL as a string for you to interpret.
Reply all
Reply to author
Forward
0 new messages