Forum Discussion
Darren_Person_2
Nimbostratus
May 07, 2007Image Leeching / Random querystring fix?
Hi All,
We have the RAMCACHE module installed and are seeing a high rate of evictions. After some further investigation, it appears that we have someone linking to our images using a random querystring (i.e.: http://site.com/img/image.jpg?random=XXXXXX
This is generating many copies of this image in our cache. Can someone explain a possible iRule solution to strip off the querystring an make it so that they can no longer do this?
In addition, do you know of any iRule which would stop someone from leeching our images. i.e.: If the image isn't being requested from one of our domains in the browser url, then send back a fake image?
Any help you could provide would be greatly appreciated!!
12 Replies
- bl0ndie_127134Historic F5 AccountCheck out example on using CACHE::uri if you are using 9.2 or later release. This rule sets the effective URI without modifying it on the wire.
- Kirk_Bauer_1018
Altostratus
You could definitely check to see if the URI requested contains the string ".jpg" and then check the "Referer" (sic) header and check to see if it comes from your sites. I don't have time to write it for you, but it should be pretty straightforward to do this sort of rule. - hoolio
Cirrostratus
There is a related example in the codeshare for restricting access to specific file types using the referer header.
Click here
Aaron - Darren_Person_2
Nimbostratus
Hi All,
Thank you for the responses. I'm going to try an example of the CacheBusterBuster in hopes that you can help fill in the blanks.
We have requests that come in for static content such as these:
http://site.com/image/image.jpg?12313
http://site.com/image/image.jpg?random=12313
http://site.com/swf/mysef.swf?r=6644
I'd like to be able to just return the object that is already in cache - here is a starting point:
iRule = CacheBusterBuster
when CACHE_REQUEST {
if { [string tolower [HTTP::uri]] contains "?" } {
CACHE::Uri [string first {?} [HTTP::uri] 0]
}
}
Please let me know if this will work or if there is a better way to do this?
Thanks! - hoolio
Cirrostratus
'[string first {?} $myUri 0]' will return an index of the first occurrence of the ? character. You could use that index in string range to get all characters up to that index:
[string range [HTTP::uri] 0 [expr [string first {?} [HTTP::uri] 0] - 1]
Or you could just use HTTP::path to get the path and object (/image/image.jpg for example) without the query string.
Aaron - Darren_Person_2
Nimbostratus
Thanks Aaron - so would this work:
iRule = CacheBusterBuster
when CACHE_REQUEST {
CACHE::Uri [HTTP::host][HTTP::path]
}
Does setting CACHE::Uri tell the CACHE to send back this file instead of [HTTP::Uri]? - hoolio
Cirrostratus
I haven't used the CACHE:: functions before as I haven't had a license for it, and I couldn't find any example rules that used CACHE::uri so I'm not very clear on the commands. But based on Bl0ndie's post (Click here), I don't think any change is made to the actual request. The change is just to what the caching module logically parses the request as.
This forces the [caching module] to store the documents under the different URI without actually changing the URI on the wire. This logic should be employed in HTTP_REQUEST event.
So per this and the wiki page, you should change the event from CACHE_REQUEST to HTTP_REQUEST.
http://devcentral.f5.com/wiki/default.aspx/iRules/CACHE__uri.html
CACHE::uri
* Overrides the URI value used by the cache to store the cached content, according to the specified string.
Maybe someone that has used the caching commands could elaborate?
Thanks,
Aaron - Darren_Person_2
Nimbostratus
I've tried to update it as follows, but I'm still seeing the cache build up on requests:
when HTTP_REQUEST {
set CACHE::Uri [HTTP::host][HTTP::path]
} - Darren_Person_2
Nimbostratus
When I do that, I get the following error:
01070151:3: Rule [CacheBusterBuster] error:
line 2: [undefined procedure: CACHE::uri] [CACHE::uri [HTTP::host][HTTP::path]] - hoolio
Cirrostratus
Are you on 9.2 or higher? It looks like the CACHE::uri command was added in 9.2.0.
I tried testing the following rule, but got an error because I don't have a unit licensed for the caching module.when HTTP_REQUEST { if {[HTTP::uri] contains "?"}{ CACHE::uri [HTTP::host][HTTP::path] } }
The command is recognized, but not licensed. If I change it to CACHE:Uri, I get an unrecognized command error.
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects