by
KK » Tue Jun 06, 2017 3:41 pm
@trendoman
@KK, would a direct file path be a huge security hole?
The location of the folder storing the uploaded attachments will certainly be divulged but, I think, if we make sure that it is not browsable directly we should be ok (the names of all files uploaded using securefile will be hashed so one cannot access any simply by knowing the folder location).
To test it, try navigating to the 'attachments' folder (by default within 'couch/uploads' but the location can be changed from config). If you are not shown a listing of all contained files (you really shouldn't if the folder is in the original location), we can proceed. If, however, you do happen to get a listing, please place a .htaccess file within the folder containing the following line -
- Code: Select all
Options -Indexes
Alternatively, simply copy 'couch/.htaccess' file and paste it into the 'attachments' folder as it contains the same directive.
OK, with that done, we can now use the 'un-obfuscated' links/paths of the uploaded files. Here is how we can do that -
Normally while working with securefiles, we use <cms:cloak_url> to output the links as follows
- Code: Select all
<cms:show_securefile 'imagefile' >
<cms:if file_is_image >
<a href="<cms:cloak_url link=file_id />">
<img src="<cms:cloak_url link=file_id />" />
</a>
</cms:if>
</cms:show_securefile>
Substitute the <cms:cloak_url /> tag with
<cms:securefile_link> tag as follows and you should now get the direct links to the files -
- Code: Select all
<cms:show_securefile 'imagefile' >
<cms:if file_is_image >
<a href="<cms:securefile_link file_id />">
<img src="<cms:securefile_link file_id />" />
</a>
</cms:if>
</cms:show_securefile>
Since this is the first reference to
<cms:securefile_link> on the forum, allow me to take the opportunity to add more info about it (will serve as ad-hoc documentation).
- Code: Select all
// securefile link uncloaked
<cms:securefile_link '32' />
<cms:securefile_link id='32' /> // http://somesite.com/couch/uploads/attachments/9e92db13d0cb40cb7003c070c3ce1dc7.jpg
<cms:securefile_link id='32' physical_path='1' /> // W:/www/couch/uploads/attachments/9e92db13d0cb40cb7003c070c3ce1dc7.jpg
<cms:securefile_link id='32' thumbnail='1' /> // ditto but for thumbnails
<cms:securefile_link id='32' thumbnail='1' physical_path='1' />
A real life example -
- Code: Select all
<cms:show_securefile 'sfile' >
<cms:if file_is_image >
<cms:set my_image_link = "<cms:securefile_link file_id />" />
<cms:set my_thumb_link = "<cms:securefile_link file_id thumbnail='1' />" />
<a href="<cms:show my_image_link />">
<img src="<cms:show my_thumb_link />" />
</a>
<cms:else />
<cms:set my_file_link = "<cms:securefile_link file_id />" />
<a href="<cms:show my_file_link />">
Download <cms:show file_name />.<cms:show file_ext />
</a>
</cms:if>
</cms:show_securefile>
@setiawanfarlin, please try using the real link for the images as shown above and let me know if it helps. Thanks.
P.S. If you happen to get a 'Tag not found error' while using this new tag, please download the latest version of Couch from GitHub -
https://github.com/CouchCMS/CouchCMS