# 400 Bad request

**URL:** <https://www.ruby-forum.com/t/400-bad-request/211816>\
**Category:** NGINX\
**Created:** [September 14, 2011, 12:49pm UTC](https://www.ruby-forum.com/t/400-bad-request/211816 "2011-09-14T12:49:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [September 14, 2011, 12:49pm UTC](https://www.ruby-forum.com/t/400-bad-request/211816/1 "2011-09-14T12:49:07Z")

</div>

Hi,

Having problems with urls containing percent sign. Most of them return  
400 and don’t even appear neither in error.log nor in access.log.

GET /download-%27.07%%27.html?frame=1 HTTP/1.1  
Host: www.my.eu  
User-Agent: Mozilla/5.0 (X11; Linux x86\_64; rv:6.0) Gecko/20100101  
Firefox/6.0 FirePHP/0.6  
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,_/_;q=0.8  
Accept-Language: en-us,en;q=0.5  
Accept-Encoding: gzip, deflate  
Accept-Charset: ISO-8859-1,utf-8;q=0.7,\*;q=0.7  
Connection: keep-alive  
x-insight: activate

HTTP/1.1 400 Bad Request  
Server: nginx/1.0.5  
Date: Wed, 14 Sep 2011 10:36:24 GMT  
Content-Type: text/html  
Content-Length: 172  
Connection: close

What’s wrong with them?

Thanks

Posted at Nginx Forum:

> **[400 Bad request](https://forum.nginx.org/read.php?2,215184,215184#msg-215184)**
>
> Hi, Having problems with urls containing percent sign. Most of them return 400 and don't even appear neither in error.log nor in access.log. GET /download-%27.07%%27.html?frame=1 HTTP/1.1 Host: www.my.eu User-Agent: Mozilla/5.0 (X11; Linux x86\_64;...

---

<div class="post-metadata">

**Author:** ![coviex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c0e974/32.png) [@coviex](https://www.ruby-forum.com/u/coviex)\
**Post date:** [September 14, 2011, 1:12pm UTC](https://www.ruby-forum.com/t/400-bad-request/211816/2 "2011-09-14T13:12:38Z")

</div>

Hello!

On Wed, Sep 14, 2011 at 06:48:25AM -0400, coviex wrote:

> Accept-Language: en-us,en;q=0.5  
> Connection: close
> 
> What’s wrong with them?

They aren’t valid.

> **[RFC 3986: Uniform Resource Identifier (URI): Generic Syntax | RFC Editor](https://www.rfc-editor.org/info/rfc3986/)**
>
> A Uniform Resource Identifier (URI) is a compact sequence of characters that identifies an abstract or physical resource. This specification defines the generic URI syntax and a process for resolving URI references that might be in relative form,...

Because the percent (“%”) character serves as the indicator for  
percent-encoded octets, it must be percent-encoded as “%25” for that  
octet to be used as data within a URI.

Maxim D.

---

<div class="post-metadata">

**Author:** ![coviex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c0e974/32.png) [@coviex](https://www.ruby-forum.com/u/coviex)\
**Post date:** [September 14, 2011, 1:13pm UTC](https://www.ruby-forum.com/t/400-bad-request/211816/3 "2011-09-14T13:13:52Z")

</div>

On Wed, Sep 14, 2011 at 06:48:25AM -0400, coviex wrote:

Hi there,

> Having problems with urls containing percent sign. Most of them return  
> 400 and don’t even appear neither in error.log nor in access.log.

% is an escape character within a url. It must be followed by exactly  
two hex-characters, or the url is invalid and the request is bad.

> GET /download-%27.07%%27.html?frame=1 HTTP/1.1

The first one there is %27 and decodes to '.

The second one is %%2 and is invalid.

> What’s wrong with them?

They’re broken.

Whatever is generating that url should be fixed so that it is properly  
encoded/escaped.

If the filename is download-‘.07%’.html, it should appear in the url  
as download-%27.07%25%27.html

All the best,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![coviex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c0e974/32.png) [@coviex](https://www.ruby-forum.com/u/coviex)\
**Post date:** [September 14, 2011, 5:25pm UTC](https://www.ruby-forum.com/t/400-bad-request/211816/4 "2011-09-14T17:25:47Z")

</div>

This query string results in 400 on all nginx servers/sites I know of.  
Say, [http://nginx.org/download-'.07%'.html?frame=1](http://nginx.org/download-%27.07%25%27.html?frame=1).  
Any suggestions?

Posted at Nginx Forum:

> **[Re: 400 Bad request](https://forum.nginx.org/read.php?2,215184,215203#msg-215203)**
>
> Hi, Having problems with urls containing percent sign. Most of them return 400 and don't even appear neither in error.log nor in access.log. GET /download-%27.07%%27.html?frame=1 HTTP/1.1 Host: www.my.eu User-Agent: Mozilla/5.0 (X11; Linux x86\_64;...

---

<div class="post-metadata">

**Author:** ![coviex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c0e974/32.png) [@coviex](https://www.ruby-forum.com/u/coviex)\
**Post date:** [September 14, 2011, 7:46pm UTC](https://www.ruby-forum.com/t/400-bad-request/211816/5 "2011-09-14T19:46:06Z")

</div>

Funny thing is there are two sibling threads on the forum named  
identically and answers to my question wind up here.

> **[400 bad request](https://forum.nginx.org/read.php?2,2757)**
>
> this is nginx 0.6.34. We run some fairly high volume facebook sites and have had problems with 400 errors now for months. It only happens on one part of our site that runs inside an iframe. At first I thought it was cookies that were too large. I...

> **[400 Bad request](https://forum.nginx.org/read.php?2,215184)**
>
> Hi, Having problems with urls containing percent sign. Most of them return 400 and don't even appear neither in error.log nor in access.log. GET /download-%27.07%%27.html?frame=1 HTTP/1.1 Host: www.my.eu User-Agent: Mozilla/5.0 (X11; Linux x86\_64;...

And I didn’t know about that so sorry for asking twice.

I get that requests with %% are invalid.  
But why they don’t appear in logs?  
Can I show pretty 404 page for those 400?

Posted at Nginx Forum:

> **[Re: 400 Bad request](https://forum.nginx.org/read.php?2,2757,215210#msg-215210)**
>
> this is nginx 0.6.34. We run some fairly high volume facebook sites and have had problems with 400 errors now for months. It only happens on one part of our site that runs inside an iframe. At first I thought it was cookies that were too large. I...

---

<div class="post-metadata">

**Author:** ![coviex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c0e974/32.png) [@coviex](https://www.ruby-forum.com/u/coviex)\
**Post date:** [September 14, 2011, 8:04pm UTC](https://www.ruby-forum.com/t/400-bad-request/211816/6 "2011-09-14T20:04:00Z")

</div>

On Wed, Sep 14, 2011 at 01:45:15PM -0400, coviex wrote:

> Funny thing is there are two sibling threads on the forum named  
> identically and answers to my question wind up here.  
> [http://forum.nginx.org/read.php?2,2757](http://forum.nginx.org/read.php?2,2757)  
> [http://forum.nginx.org/read.php?2,215184](http://forum.nginx.org/read.php?2,215184)  
> And I didn’t know about that so sorry for asking twice.
> 
> I get that requests with %% are invalid.  
> But why they don’t appear in logs?  
> Can I show pretty 404 page for those 400?

nginx logs this on “info” level:  
“client sent invalid request while reading client request line”

The default error\_log level is “error”.

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![coviex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c0e974/32.png) [@coviex](https://www.ruby-forum.com/u/coviex)\
**Post date:** [September 14, 2011, 5:31pm UTC](https://www.ruby-forum.com/t/400-bad-request/211816/7 "2011-09-14T17:31:21Z")

</div>

On Wed, Sep 14, 2011 at 11:25:24AM -0400, coviex wrote:

> This query string results in 400 on all nginx servers/sites I know of.  
> Say, [http://nginx.org/download-'.07%'.html?frame=1](http://nginx.org/download-%27.07%25%27.html?frame=1).

Not only nginx. Apache does (correctly) the same:

$nc [apache.org](http://apache.org) 80  
GET /download-%27.07%%27.html HTTP/1.0

HTTP/1.1 400 Bad Request  
Date: Wed, 14 Sep 2011 15:29:31 GMT  
Server: Apache/2.3.15-dev (Unix) mod\_ssl/2.3.15-dev OpenSSL/1.0.0c  
Content-Length: 342  
Connection: close  
Content-Type: text/html; charset=iso-8859-1

[…]

> Any suggestions?

-[http://nginx.org/download-'.07%'.html?frame=1](http://nginx.org/download-%27.07%25%27.html?frame=1)  
+http://nginx.org/download-%27.07%25%27.html?frame=1

–  
Igor S.
