Dirty and Quickie deep linking prevention

George Notaras gnot at g-loaded.eu
Fri Sep 25 21:32:45 EEST 2009


rouvas at di.uoa.gr wrote:
> Christos Ricudis wrote:
>> Exete bare8ei na linkarei olo to sympan to directory sas me tis
>> 452973493 lolcats apo diafora hli8ia forums?
>>
>> Taiste tous ena Cthulhu Goatse!
>>
>> mod_perl required. Modify it to suit your site.
>>
>> apache.conf :
>>
>> PerlModule Perlomodula::Taisthri
>> PerlTransHandler Perlomodula::Taisthri
>>
>> Taisthri.pl :
>>
>> package Perlomodula::Taisthri;
>>
>> use strict;
>> use Apache2::RequestRec ();
>> use Apache2::Log ();
>> use APR::Table ();
>> use Apache2::Const -compile => qw(DECLINED);
>>
>> sub handler {
>>   my $r = shift;
>>
>>   my $kot=$r->uri();
>>   my $lala=$r->headers_in->{Referer} || '';
>>   my $isimage=0;
>>   my $islinked=0;
>>
>>   if
>> (!($lala=~m/.*(localhost|myserver|127.0.0.1|192.168|mydomain.com).*/i)) {
>>     $islinked=1;
>>   }
>>
>>   if ($kot=~m/(.*)\/pictures\/lolcats\/(.*)\.jpg/i) {
>>     $isimage=1;
>>   }
>>
>>   if (($islinked==1)&&($isimage==1)) {
>>     $r->uri("/cthulhu-goatse.jpg");
>>     $r->log_error("Bad referer $lala linked to $kot, fed him a
>> goatse-cthulhu");
>>   }
>>
>>   return Apache2::Const::DECLINED;
>>
>> }
>> 1;
>>
> 
> Ginetai kai me to mod_rewrite tou Apache, kapos etsi:
> 
> <IfModule mod_rewrite.c>
>   RewriteEngine On
> 
>   RewriteCond %{HTTP_REFERER} .*myspace.*
>   RewriteRule  .*                 /dont-link-to-me  [G]
> 
>   RewriteCond %{HTTP_REFERER} .*hi5.*
>   RewriteRule  .*                 /dont-link-to-me  [G]
> 
>   RewriteCond %{HTTP_REFERER} .*youtube.*
>   RewriteRule  .*                 /dont-link-to-me  [G]
> </IfModule>
> 
> sto .htaccess tou directory.
> 

Με αυτό όμως πιάνεις όλα τα links από τα παραπάνω sites...

Το παρακάτω είναι νομίζω καλύτερο και επιστρέφει και πιο χρήσιμο error code:

<IfModule mod_rewrite.c>
  RewriteCond %{HTTP_REFERER} !^http\:\/\/DOMAIN\.TLD\/
  RewriteRule \.(jpg|jpeg|png|gif)$ http://DOMAIN.TLD/stopleeching.html
[R=302,L]
</IfModule>

Δεν είμαι σίγουρος ότι χρειάζεται escaping o referrer.




More information about the Linux-greek-users mailing list