In a web application to transform images I want to deny direct access to other user's images and I've achieve it adding this code at my main .htaccess
file:
RewriteCond %{HTTP_COOKIE} !PHPSESSID=(.+) [OR,NC]
RewriteCond %{HTTP_COOKIE}:%{REQUEST_URI} ^PHPSESSID=(.*?);:(?!.*?/usuarios/\1).* [NC]
RewriteRule ^.*?/usuarios/.+?\.(gif|jpe?g|png|wbmp)$ - [R=403,L]
So, as users have their own folder to upload and transform images, this rule will check if you are looking for an image which directory matches with your id_session
, and will throw a 403 response if it doesn't match.
It seems to work fine, but if any user attach an image and change the scr
with other user's image (assuming he knows the path), it is showing that image.
How could I prevent it?
You can check at http://itransformer.es