|
Cookbook /
SecureAttachmentsSummary: Security issues for attachments
Version:
Prerequisites: Requires at least PmWiki version: 2 beta 31
Status:
Maintainer:
Questions answered by this recipeHow do I protect page and group attachments when the page or group is read-protected by a password? AnswerYou need to protect the files in the uploads directory from public access (step 1) and change PmWiki's default mechanism of using the
This will disable pmwiki's default mechanism of converting the Attach:filename.ext markup to a url pointing directly to the file, like http://mysite.com/pmwiki/uploads/SomeGroup/filename.ext, and uses ?action=download instead, like http://mysite.com/pmwiki/pmwiki.php?n=SomeGroup.SomePage&action=download&upname=filename.ext.Thereby the standard page or group password protection applies to the attachments as well. Note about securityIn case of the default per-group uploads directory structure (see UploadGroups and Notes and Comments(from the pmwiki-users list:) By default when PmWiki generates "Attach:" links, it creates them as "direct" links into the webserver directory. For example, in the Cookbook the markup " This has some advantages and disadvantages. The biggest advantage is that it's fast, in that the webserver doesn't have to execute a PHP script in order to return the appropriate file to the browser. The webserver can also take care of determining the appropriate Content-Type for the file. However, a big disadvantage is that all attachments are publicly accessible as long as someone knows the URL. In addition, there are some environments (examples include IIS and sourceforge.net) where the webserver disallows direct access to files that have been created by a PHP script. As a result, beta31 now offers an ?action=download option, which can be used to retrieve a page's attachment. For example, with This provides some important features:
Of course, the downside of this is that accessing an attachment a somewhat heavier load on the server, since it now involves running a PHP script and determining the page's permissions before the file can be transmitted. Still, for sites that want to use PmWiki's authorization system to restrict access to attachments, or that are on webservers that disallow accessing the attachments directly, this is an incredibly useful feature and the trade-offs in performance isn't important. --Pm If you want to handle attachments using PmWiki access control but would also like to have clean URLs for your uploads, this is possible using Apache's mod_rewrite (see Cookbook.CleanUrls for more info). To achieve this, do as follows:
RewriteRule ^attach/(.+)/([^/]+)$ path/to/pmwiki.php?n=$1&action=download&upname=$2 [QSA,L]
$UploadUrlFmt = '/attach';
--EemeliAro February 06, 2008 See Also
Contributors |