How should I configure my ElasticBeanstalk on AWS to allow encoded slashes in URLs ? (Using -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true)
I've created a directory called .ebextensions with a file tomcat.config in top-level directory of my source bundle (http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html) with the content:
commands:
allow-encoded-slash:
command: export CATALINA_OPTS="$CATALINA_OPTS -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true"
cwd: /home/ec2-user
But it seems it has no effect, it doesn't appear in these dirs:
ls -la /tmp/deployment/application/ROOT/
ls -la /var/lib/tomcat7/webapps/ROOT/
We also tried to set the ALLOW_ENCODED_SLASH system property through the Edit Configuration dialog in the Elastic Beanstalk console. But, although the property seems to be present, Tomcat still doesn't let us use encoded slashes (%2F).
We think the ALLOW_ENCODED_SLASH system property is properly set because:
1) We see that property in the java command that starts Tomcat:
2) And because we also get "true" when executing this from our web application:
Does anyone know why Tomcat is still rejecting encoded slashes?
For example, this URL should return a JSON saying "Application not found: A/1":
But, instead, it says:
The requested URL /v1/campaigns/application/A/1/udid/U1 was not found on this server.
It's strange because we have tried the ALLOW_ENCODED_SLASH system property in a local Tomcat and it works fine.
Lately we tried another property. This ones works both in my local Tomcat and in AWS:
I'm completely puzzled... :-/
Note that if you have an apache httpd in front of the tomcat both need to be configured to allow slashes
for tomcat the property is -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true (best placed in CATALINA_OPTS in the tomcat conf file)
for apache the directive AllowEncodedSlashes needs to be set to NoDecode furthermore the ProxyPass directive needs to be set to nocanon otherwise tomcat will recieve an encoded slash as %252F instead of %2F
So the correct apache configuration looks like this:
An ElasticBeanstalk has an apache (I guess for the Load Balancer) on front of Tomcat, so this is the first one who receives a request, and is where must be indicated that slashes must be not decoded.
In order to get this, we have used this virtualhost:
This URL is helpful to configure an EBS and his apache http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html