Plugin Author
AITpro
(@aitpro)
Not sure if the Zone Delegation errors actually mean there is a problem there.
Anyway I used a custom DNS Finder script for your domain and these are the IP Addresses that are returned in the results.
Server IPs
173.245.61.18
173.245.60.18
Name Server IPs
109.123.122.191
173.245.58.136
173.245.59.144
So give these IP’s a try first and see what happens:
SetEnvIf Server_Addr "^173.245.61.18$" whitelist
SetEnvIf Server_Addr "^173.245.60.18$" whitelist
Then try all IP’s including the CloudFlare Name Servers
SetEnvIf Server_Addr "^173\.245\.61\.18$" whitelist
SetEnvIf Server_Addr "^173\.245\.60\.18$" whitelist
SetEnvIf Server_Addr "^109\.123\.122\.191$" whitelist
SetEnvIf Server_Addr "^173\.245\.58\.136$" whitelist
SetEnvIf Server_Addr "^173\.245\.59\.144$" whitelist
or maybe you would have to do something like this:
SetEnvIfNoCase Referer "^(http|https)://www\.matchlessclueless\.com$" whitelist
SetEnvIfNoCase Referer "^(http|https)://.*google.*" whitelist
SetEnvIfNoCase Referer "^(http|https)://.*yahoo.*" whitelist
SetEnvIfNoCase Referer "^(http|https)://.*bing.*" whitelist
SetEnvIf Server_Addr "^173\.245\.61\.18$" whitelist
SetEnvIf Server_Addr "^173\.245\.60\.18$" whitelist
<FilesMatch "\.(gif|jpg|jpeg|png|bmp)$">
Order Allow,Deny
Allow from env=whitelist
Allow from 109.123.122.191
Allow from 173.245.58.136
Allow from 173.245.59.144
</FilesMatch>
or another possibility is that the you would need to use X-forwarded-for conditions
SetEnvIfNoCase Referer "^(http|https)://www\.matchlessclueless\.com$" whitelist
SetEnvIfNoCase Referer "^(http|https)://.*google.*" whitelist
SetEnvIfNoCase Referer "^(http|https)://.*yahoo.*" whitelist
SetEnvIfNoCase Referer "^(http|https)://.*bing.*" whitelist
SetEnvIf X-FORWARDED-FOR "^173\.245\.61\.18$" whitelist
SetEnvIf X-FORWARDED-FOR "^173\.245\.60\.18$" whitelist
<FilesMatch "\.(gif|jpg|jpeg|png|bmp)$">
Order Allow,Deny
Allow from env=whitelist
Allow from 109.123.122.191
Allow from 173.245.58.136
Allow from 173.245.59.144
</FilesMatch>
Plugin Author
AITpro
(@aitpro)
Is this issue/problem resolved? If so, please resolve this Thread. If not, please post a status update. Thank you.
Thread Starter
James
(@en7jos)
Hi. It’s not quite resolved yet as I’ve not had chance to experiment further with your above suggestions, but here’s a quick progress update:
I have left the Server_Addr commented out for the past week or so and have not observed any problems in the front end or backend, and hotlinking protection is working as required (i.e. allowing hotlinking from the whitelisted sites but blocking from anywhere else). This makes me think that the server_addr line is not required for my particular configuration.
Having given some thought to this over the past few days, it is important to point out that the problem I have with the server_addr line is that it seems to open up the hotlinking protection whitelist to every website. Hence nothing gets blocked with this line in place as every request is whitelisted. With the line commented out, only the specified sites are whitelisted as expected.
So why would this line lead to every request being whitelisted and all hotlinks being allowed? I’m not sure, but this was why I mentioned the difference between server_addr and remote_addr. If server_addr is as you explained above “the IP address of the server under which the current script is executing”, then is the script the htaccess file and hence is this no always running on my server, irrespective of where the request came from? Could this explain why this line seems to whitelist everything?
I haven’t played around with adding the various other server addresses to my whitelist yet because, as stated above, it is not a problem with allowing legitimate requests through. The problem is that the server_addr line seems to whitelist everything, hence I don’t think adding more of these lines will help. It’s not like some of my legitimate requests are getting accidentally blocked.
Maybe I need to completely remove my actual server_addr and only have the CloudFlare or X-forwarded addresses instead? But as I say, there doesn’t seem to be anything legitimate that is getting blocked without these lines of code, so its not exactly clear what exactly I am trying to allow through!
Cheers for all your help and suggestions, and any further ideas will eb gratefully received.
James 🙂
Thread Starter
James
(@en7jos)
Sorry, I meant to ask, do you know any specific example of requests that the server_addr is designed to whitelist and prevent being blocked? You mentioned before the WP backend, but everything there seems fine. Maybe this is just a quirk of my particular setup though.
Thanks again, James
Plugin Author
AITpro
(@aitpro)
I’m not sure why the code is not working correctly on your site. The code is correct. You would test it by creating a hotlink to an image file on another one of your domains that is not whitelisted.
Example:
Hotlink protection on domain websiteA.com
create a hotlink to an image file from websiteB.com to websiteA.com
Plugin Author
AITpro
(@aitpro)
Actually you are correct. I’m not sure where the screw up was, but something is off. Removing the Server IP whitelist condition does work and I do not see any image problems in the backend of the site. Jeez not sure how this info got mucked up. Will do some further testing to try and figure out why the Server IP was added and if it is actually really needed at all. I have a feeling it just got lumped together with other code by mistake during a test.
Thread Starter
James
(@en7jos)
Good to hear it’s not just me then! 🙂
Thanks for your efforts with this, hope you have more success coming to a solution than I have!
James
Plugin Author
AITpro
(@aitpro)
Ok I found the mistake staring me right in the face DOH!
It is not valid to have the Server_Addr condition and the Referer conditions together like this. There is another way to do this with SetEnvIf and this was just a mistake.
SetEnvIf Server_Addr "^173\.201\.92\.1$" whitelist
What was intended was to additionally add the Server IP address under the FilesMatch section of code. It is not really necessary, but would add an additional layer of protection to image files.
Allow from 173.201.92.1
SetEnvIfNoCase Referer "^(http|https).*.ait-pro\.com.*$" whitelist
SetEnvIfNoCase Referer "^(http|https)://.*google.*" whitelist
SetEnvIfNoCase Referer "^(http|https)://.*yahoo.*" whitelist
SetEnvIfNoCase Referer "^(http|https)://.*bing.*" whitelist
<FilesMatch "\.(gif|jpg|jpeg|png|bmp)$">
Order Allow,Deny
Allow from env=whitelist
Allow from 173.201.92.1
</FilesMatch>
Thread Starter
James
(@en7jos)
Ok, that makes sense, I’ll give it a whirl. So here’s what I now have in my custom code:
# The main domain\.tld for the website
SetEnvIfNoCase Referer "^http://(www\.)?mywebsite\.com.*" whitelist
SetEnvIfNoCase Referer "^http://(www\.)?mywebsite\.co.uk.*" whitelist
# Allow empty referrers
# SetEnvIf Referer "^$" whitelist
# List of any another domains that should be able to access the files
SetEnvIfNoCase Referer "^http://(www\.)?friendswesbite\.com.*" whitelist
SetEnvIfNoCase Referer "^http://(www\.)?friendswesbite\.net.*" whitelist
SetEnvIfNoCase Referer "^http://(www\.)?friendswesbite\.co.uk.*" whitelist
# Allow search engines to access images
SetEnvIfNoCase Referer "^(http|https)://.*google.*" whitelist
SetEnvIfNoCase Referer "^(http|https)://.*yahoo.*" whitelist
SetEnvIfNoCase Referer "^(http|https)://.*bing.*" whitelist
# Specify image file types to protect from hotlinking
<FilesMatch "\.(gif|jpg|jpeg|png|bmp)$">
Order Allow,Deny
Allow from env=whitelist
Allow from XXX.XXX.XXX.XXX
</FilesMatch>
Plugin Author
AITpro
(@aitpro)
I don’t think you want to allow empty referers. empty referers are typically spammers or hackers running some kind of script against your website or hiding the referer. So I would remove that code.
Thread Starter
James
(@en7jos)
Yep, that’s why that line is commented out (isn’t it?). It’s useful sometimes to allow direct access to images; I thought I might need to use it in the future for testing etc, so have left it in commented out so that it’s easy to re-add later if and when I need to. Save me having to find the right syntax again!
Plugin Author
AITpro
(@aitpro)
Oh ok I did not see that it was commented out.
Thread Starter
James
(@en7jos)
Right, done some testing and everything seems to be working correctly using the above code! Hotlinking is allowed from ‘mywebsite’ and ‘friendswebsites’ but blocked from elsewhere.
For testing whether hotlinking protection is working on a website, I’ve found the following tool very useful (but remember to ckear your browser cache before testing!):
http://coldlink.com/htm/tool.htm
Thanks for all your help getting to the bottom of this one 🙂