Have you heard of CloudProxy? It’s a WAF (website firewall) service offered by Sucuri, one of the most trusted names in cloud-based security technology. When looking at WAF and CDN solutions I often times came up disappointed. I always wanted a combined version that kicked ass, but never really found it. When I did find something that I thought was promising the cost was outrageous. I recently set out to create a combined hybrid of CloudProxy WAF with MaxCDN (total cost $35/mo with a max under $100/mo) and here’s the result:
As of the publication date if you are using SNI on the IP associated with the domain, you’re out of luck. Scroll down to “A Note About SSL” to read more about SNI.
Most CDNs (content delivery networks) either offer nothing more than a CDN or combine the CDN with a WAF (website firewall). The two most commonly known that combine these services are Cloudflare and Incapsula. MaxCDN is a pure CDN solution (for the most part), while CloudProxy is a WAF. CloudProxy does function as a CDN, although not really advertised. The CloudProxy WAF is not really a full featured CDN solution, doesn’t allow per file purging or custom domain names. Both CloudFlare and Incapsula (the two that combine both a CDN and a WAF) are very pricy especially when you opt for DDOS protection. In addition, both Incapsula and Cloudflare have come under heavy fire due to the amount of bypassed SQL injections XSS and LFI/RFI attacks allowed through. So wouldn’t it be nice if you could have both a CDN and a really good WAF with DDOS Protection at a fraction of the price. Well you can, and here’s how:
There’s already a guide for this, right?
Both MaxCDN and CloudProxy have a guide for setting up a CDN with the CloudProxy WAF. The guide assumes that the CDN is a mirror of the website (which isn’t the case with WordPress and W3TC). In the scenario presented by the guide all traffic passes through the CDN, then through the WAF and eventually to your server. This is a bit much and although it’s lickity split, it does create another few hops. We’re going let W3TC assign the correct cname to static content, therefore serving it from the CDN edge servers, all the while passing the rest of the dynamic, non-CDN content, through the CloudProxy WAF.
When you request a website through your browser your request goes through a series of procedures. First your browser attempts to locate the IP address to the server hosting the website. This is done through a DNS request. DNS can be subject to DDOS attacks, therefore transferring your DNS to CloudProxy is a good option to thwart these attacks. In the DNS phase there’s a few other things that happen including load-balancing, round robin etc, but those aren’t specific to this tutorial. After the IP is found the browser makes a GET request to the server, the browser identifies itself, and states the types of responses that it will accept. Normally, the IP address would be that of your server. However, because we have setup CloudProxy the IP address is now that of the Firewall. This first GET request is used to determine if the request is from a browser, bot, spammer, DDOSer etc. If the Firewall determines that the requester should be blocked they reach the end of the road. If the firewall determines that they should be let through, the GET request is sent to the server. The server then handles the request and sends back an HTML response. This response contains the urls of the static content which will be served by the CDN. The browser then begins rendering the content.
This provides the best of both worlds. The CDN is pushing the heavy weight of static content while the WAF is filtering the requests made to the server. If someone uses a direct link to the static content there’s not an issue because the content is cached on the edge servers and the request is never passed through to the server. When the CDN attempts to refresh the cached content it will obtain the new content without going through the WAF. There’s no reason for the CDN to be filtered by the WAF.
Another great reason to go this route is to avoid double caching. If the CDN retrieved its content through the WAF the WAF would be caching the content as well. This would mean that in order to purge the cached content you would need to clear it from both places. If you have a website with a lot of traffic this would be almost impossible because you would have to clear the content from both places before someone requested the content again. Another limitation to the CloudProxy WAF is that specific files cannot be purged. Because we’re serving dynamic content through the firewall, you should never have to purge the cache from CloudProxy. Any changes to CSS or JS should be purgable through MaxCDN.
The setup includes a WordPress website, W3 Total Cache, MaxCDN and CloudProxy.
The basics of this will be serve the static content, as usual, to the CDN for distribution on the edge servers. All dynamic content will be routed through the WAF.
1 – We will enable MaxCDN
2 – We are going to use w3tc (a free WordPress plugin) and set it up for connection to MaxCDN.
3 – We will setup CloudProxy
4 – We will modify DNS entries
MaxCDN will be setup just like you would normally setup a pull zone. There’s nothing special that you need to do in order to get it working correctly. If you are going to serve content over https make sure that you upload your certificate so that it works properly. Create as many Custom Domains as you want for custom URLs. I would suggest purchasing the flex locations if you plan on serving content to other countries, especially Asia and Australia.
In the guide for setting up MaxCDN with CloudProxy you are told to enable XFF and also the Origin Information. If you want to serve your static content through the firewall you can enable these options and set them up as described in the guide supplied by CloudProxy. Whenever content is retrieved from the server it will first pass through the CloudProxy. If you would rather just get the static content from your server directly leave the XFF disabled. The next paragraph will talk about the Origin Information and why we have to enable it anyway. We don’t feel that there is a substantial need to go through the firewall since the content will be delivered from cache over 90% of the time.
MaxCDN will automatically grab the IP address of your server. It’s important to note that because we will be changing the A record we need to manually tell MaxCDN where the server is located in order to get the files directly from the server and bypass the CloudProxy firewall. To do this we need to modify Origin Information on the settings page. Your settings should now look like this (replace the X’s with your server iP):
Your Edge settings should look like this:
W3TC will be setup in the same manner as it normally would. Nothing special about the settings here. There’s a mountain of information on the interwebs on how to setup W3TC if you are unfamiliar. Of course make sure the CDN is set to MaxCDN.
Once you have signed up for CloudProxy and you’ve followed the instructions to setup the domain, you’ll be presented with the settings page. At the very bottom of the settings page you’ll see an area for CDN. We want to make sure that it’s set to “None”. Even if you decide to send your CDN content through the firewall you’ll still want to set it to “none”. It’s very important that you ignore basically everything in this box.
Make sure that you submit your SSL certificate to them if you plan on https access to the website.
A Note About SSL: As of this publishing date SNI (Server Name Indication) is not supported. The certificate added in Sucuri must match the certificate associated with the IP on your server. Therefore, this will not work on shared hosting platforms without a dedicated IP address. For that matter, a dedicated server with multiple SSL certificates on a single IP will not work. Subdomains etc are fine so long as you’re not passing subdomain traffic through the firewall. If you are, then you’ll need a wildcard SSL, which we’ve confirmed works well.
Now we have a couple options. You can click on the DNS tab and follow the instructions to have your DNS re-routed through Sucuri or you could leave it as be. In our deployment we left it alone and continued to use our DNS servers. Next step would be to get the IP addresses that are listed as the Firewall IP Addresses. These are shown below your hosting IP address in the settings page of CloudProxy. Once you have these two IP addresses you’ll need to proceed to the next step.
Setup Your DNS
In your web hosting control panel modify the appropriate DNS A records to point to the IP addresses for the CloudProxy firewall. Once the DNS propagation is complete traffic will begin to flow through the firewall.
Preventing Direct Access
If someone knows your hidden Hosting IP address, they can bypass the CloudProxy firewall and try to access your server directly. It is not common or easy to do, but for additional extra security, we recommend only allowing HTTP access from the firewall and CDN. In order to do this we need to add the following to the .htaccess file in your web hosting root folder:
<FilesMatch ".*"> Order deny,allow Deny from all #Begin CloudProxy Allow from 184.108.40.206 Allow from 220.127.116.11 Allow from 18.104.22.168 Allow from 22.214.171.124 Allow from 126.96.36.199 Allow from 188.8.131.52 Allow from 184.108.40.206 Allow from 220.127.116.11 Allow from 18.104.22.168 Allow from 22.214.171.124 Allow from 126.96.36.199 Allow from 188.8.131.52 Allow from 184.108.40.206 Allow from 220.127.116.11 Allow from 18.104.22.168/24 Allow from 22.214.171.124/24 Allow from 126.96.36.199/24 Allow from 188.8.131.52/24 Allow from 184.108.40.206/16 Allow from 220.127.116.11/16 #Begin MaxCDN Allow from 18.104.22.168/21 Allow from 22.214.171.124/20 Allow from 126.96.36.199/24 Allow from 188.8.131.52 Allow from 184.108.40.206/27 Allow from 220.127.116.11/27 Allow from 18.104.22.168/27 Allow from 22.214.171.124 Allow from 126.96.36.199/27 Allow from 188.8.131.52/27 Allow from 184.108.40.206/27 Allow from 220.127.116.11 Allow from 18.104.22.168/27 Allow from 22.214.171.124/27 Allow from 126.96.36.199/27 Allow from 188.8.131.52 Allow from 184.108.40.206/27 Allow from 220.127.116.11/27 Allow from 18.104.22.168/32 Allow from 22.214.171.124 Allow from 126.96.36.199/22 Allow from 188.8.131.52/32 Allow from 184.108.40.206/32 Allow from 220.127.116.11 Allow from 18.104.22.168/32 Allow from 22.214.171.124/32 Allow from 126.96.36.199 Allow from 188.8.131.52/32 Allow from 184.108.40.206 Allow from 220.127.116.11/21 </FilesMatch>
Please note that these IP addresses may need to be changed as time goes on and IP addresses are removed or added. If you’d like to use this guide with a different CDN please make the correct modifications to the list. Here’s the links to the current list of IP addresses:
CloudProxy – List can be found in your security settings tab
From all of us at WireFlare we ask that you help others find the answers they are looking for. Please leave a comment or share this post!
I'm the President of WireFlare. I have a passion for creativity, online business and internet security. I strive to create a community that empowers people to be themselves. I'm an adventurist, fun loving and caring. Find me hiking in places most people don't dare to go!