tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cai, Charles [COMRES/RTC/RTC]" <>
Subject RE: Question about Tomcat Virtual Host to prevent Improper-Input-Handling attack
Date Tue, 23 May 2017 13:05:15 GMT

Charles Cai | T +1 440 329 4888

-----Original Message-----
From: André Warnier (tomcat) [] 
Sent: Monday, May 22, 2017 3:19 PM
Subject: Re: Question about Tomcat Virtual Host to prevent Improper-Input-Handling attack

On 22.05.2017 20:35, Cai, Charles [COMRES/RTC/RTC] wrote:
> Hi there,
> ______________________________________________________________________
> __________
> Server Specs:
> Server version: Apache Tomcat/7.0.54
> Server built:   May 19 2014 10:26:15
> Server number:
> OS Name:        Windows Server 2012
> OS Version:     6.2
> Architecture:   amd64
> JVM Version:    1.8.0_121-b13
> JVM Vendor:     Oracle Corporation
> ______________________________________________________________________
> __________
> I'm currently on the process of trying fix a site vulnerability, basically it is one
type of the "Improper Input Handling" attack.
> Let's say my website is and there is hacker's 
> website
> whenever there is a request send to with modified "Host" header point
to, my site will create a redirect to along with whatever
the url it was. e.g.
> Normal:
> Host:
> Response 200 ok
> Hack:
> Host: (#been manually modified) GET  
> Response 302
> Send another Redirect to My website 
> is running on Tomcat 7, I tried some solution with set up the virtual host by point the
unknown host to a defaultlocalhost which supposed to do nothing. but it still send the redirect
for some reason.
> Here attached is my server.xml host configure:
> ______________________________________________________________________
> __________ <Engine name="Catalina" defaultHost="defaultlocalhost" 
> jvmRoute="jvm1"> <Host name=""  appBase="webapps"
>          unpackWARs="true" autoDeploy="false" deployOnStartup="true">
>      <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
>             prefix="localhost_access_log." suffix=".txt"
>             pattern="%h %l %u %t &quot;%r&quot; %s %b" />
>    </Host>
>    <Host name="defaultlocalhost"  >
>    </Host>
> ______________________________________________________________________
> __________ So, my question is, Am I on the right track to prevent this 
> kind of attack ? If yes, what I did wrong that still not working? (The 
> ultimate goal is, if it is not the legit Host that been passed in, the 
> request should be discard/ignored/return 404 but not redirect with 
> 302)

The first thing is, as far as I know, Tomcat *by itself* will not generate this redirect response.
But an application deployed inside Tomcat might do that, perhaps.

With the above configuration, this is what happens :

 > <Engine name="Catalina" defaultHost="defaultlocalhost" jvmRoute="jvm1">

 >    <Host name="defaultlocalhost"  >
 >    </Host>

1) Any request coming in to your server, which has a Host: HTTP header which is not "recognised"
by Tomcat, will be processed by this "defaultlocalhost" virtual Host.
See :

2) this default virtual Host, as defined above, has an appBase="webapps", just like the other
Host which you defined.
That is because "webapps" is the *default* value for this attribute, and you did not specify
it otherwise in your "defaultlocalhost".
See :

3) thus, if your normal application corresponding to the URI get/some/resources/) is deployed
under (tomcat_dir)/webapps, then your application will be called when anyone sends the following
HTTP request to your server :

GET get/some/resources/ HTTP/1.1
Host: (or whatever is not "")

What your application then does with this call, is up to your application.
If it is some kind of framework, it might very well decide to return a redirect response.
But that is not tomcat code.

If you want to protect against this, then you should provide your "defaultlocalhost" with
a real appBase, different from the standard "webapps", and maybe put a default application
there which returns a lit cluster bomb to the evil hacker.
(or more reasonably, a "not found" response; which tomcat will do by itself if there is nothing
there that matches the request URI).

Note that in addition, with your above configuration, there should be warnings in the tomcat
logfile, because your application will be deployed twice : once for the "defaultlocalhost"
Host, and once for the "" Host.

> Thank you in advance.
> More references about the attack here :
> ks.html 
> ing
> Original Post on stackoverflow:  
> event-improper-input-handling-attack
> Charles Cai | Web Application Developer | RIDGID Emerson Commercial & 
> Residential Solutions |
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

That is , this is the issue, after I point the defaultlocalhost to a non-existing webapp directory,
it returned 404 instead of issue another redirect with 302. Thank you very much.  

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message