How protect files in var directory?

Author Message

Tomasz Jakubowski

Wednesday 01 August 2007 11:54:27 pm

I create content with image. Content is in protect area (need login to see it). But if I put direct link to image file in browser I can see it.
So, system isn't protected from access without login.

If there any solution to protect files in var directory?

André R.

Thursday 02 August 2007 12:37:39 am

Remove the rewrite rules that lets users download images directly from var.
It will be a lot slower, but it will check access rights on every image request.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Tomasz Jakubowski

Thursday 02 August 2007 2:47:05 pm

Thanks for your response but I still have a problem with that.

I remove the rewrite rules for var directory. But now I can't see any images on my site. The same behaviour for admin user and anonymous user. When I put direct image link (like: http://example.com/var/siteaccess/storage/images/folder/zdjecie/1579-1-pol-PL/zdjecie_large.jpg) to browser then I get eZ error page with error message: The requested module var could not be found.

If there any special configuration options?

My configuration of eZ Publish - virtual host.
My .htaccess file:

DirectoryIndex index.php

<FilesMatch "(index\.php|\.(gif|html|css|jpe?g|png|ico|js|asf|avi|wmv|swf|xsl|jar|pdf|doc))$">
order allow,deny
allow from all
Options FollowSymLinks Includes ExecCGI
</FilesMatch>

RewriteEngine on

RewriteBase /

# first we rewrite the root dir to the handling php script
RewriteRule ^$ index.php [L]
RewriteRule ^index\.html$ index.php [L]

# exclude here directories or files eg. your webmail, phpadsnew, pphlogger
#Rewriterule ^var/storage/.* - [L]
#Rewriterule ^var/[^/]+/storage/.* - [L]
#RewriteRule ^var/cache/texttoimage/.* - [L]
#RewriteRule ^var/[^/]+/cache/texttoimage/.* - [L]
Rewriterule ^design/[^/]+/(stylesheets|images|javascript)/.* - [L]
Rewriterule ^share/icons/.* - [L]
Rewriterule ^extension/[^/]+/design/[^/]+/(stylesheets|images|javascripts?)/.* - [L]
Rewriterule ^packages/styles/.+/(stylesheets|images|javascript)/[^/]+/.* - [L]

RewriteRule .* index.php [L]

André R.

Friday 03 August 2007 5:30:24 am

Sorry for giving you wrong advice, seems like only files (as in word, pdf etc) can be server like this true content/download.

Images are protected in the way that if you don't have access to it, you will get text saying "you don't have access to this image" instead of the image. So basically you only get the link if you have access, given that you use the ez templates for generating the url / image tag.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 10:20:23
Script start
Timing: Jan 18 2025 10:20:23
Module start 'layout'
Timing: Jan 18 2025 10:20:23
Module start 'content'
Timing: Jan 18 2025 10:20:23
Module end 'content'
Timing: Jan 18 2025 10:20:23
Script end

Main resources:

Total runtime0.7771 sec
Peak memory usage4,096.0000 KB
Database Queries60

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0057 589.0469152.6250
Module start 'layout' 0.00570.0026 741.671939.4453
Module start 'content' 0.00830.7674 781.1172551.2344
Module end 'content' 0.77570.0013 1,332.351612.4688
Script end 0.7771  1,344.8203 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00370.4796160.0002
Check MTime0.00170.2199160.0001
Mysql Total
Database connection0.00080.101510.0008
Mysqli_queries0.721892.8771600.0120
Looping result0.00060.0728580.0000
Template Total0.735894.720.3679
Template load0.00210.276220.0011
Template processing0.733694.401120.3668
Template load and register function0.00050.068310.0005
states
state_id_array0.00470.610310.0047
state_identifier_array0.00100.125520.0005
Override
Cache load0.00180.2338210.0001
Sytem overhead
Fetch class attribute can translate value0.00080.106920.0004
Fetch class attribute name0.00140.185450.0003
XML
Image XML parsing0.00070.084520.0003
class_abstraction
Instantiating content class attribute0.00000.003760.0000
General
dbfile0.00350.4515170.0002
String conversion0.00000.000940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
5content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 17
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs