user-access-manager icon indicating copy to clipboard operation
user-access-manager copied to clipboard

File locking does not work when locked directory type Wordpress is selected

Open bunglegrind opened this issue 6 years ago • 6 comments

On a clean install, WP 5.2, with UAM latest stable, if I lock files with locked directory type option Wordpress selected, the locking does not work. Specifically, the rule created by UAM:

RewriteCond %{REQUEST_URI} ^.*\[0-9]{4}\[0-9]{2}.*$

in .htaccess does not match the uri. (example: http://wp.localhost/wp-content/uploads/2019/05/doe.pdf

Complete .htaccess: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_URI} !.*\/sites\/[0-9]+\/.* RewriteCond %{REQUEST_URI} ^.*\[0-9]{4}\[0-9]{2}.*$ RewriteRule ^([^?]*)$ /index.php?uamfiletype=attachment&uamgetfile=$1 [QSA,L] RewriteRule ^(.*)\?(((?!uamfiletype).)*)$ /index.php?uamfiletype=attachment&uamgetfile=$1&$2 [QSA,L] RewriteRule ^(.*)\?(.*)$ /index.php?uamgetfile=$1&$2 [QSA,L] </IfModule>

In Settings->media "Organize my uploads into month- and year-based folders" is checked.

The problem is, in addition to the wrong regexp expression, that the "wordpress" option only checks the uri against the regexp expression, instead of checking all the media database to verify if the requested file is matching one of the WP media.

I kindly suggest you to rephrase the sentence above accordingly

bunglegrind avatar May 15 '19 13:05 bunglegrind

So, the issue concerns the PHP constant DIRECTORY_SEPARATOR which you are using in the RewriteCond rule in the getDirectoryMatch() methods. You should use a forward slash since you're matching a uri not a file path.

bunglegrind avatar May 17 '19 07:05 bunglegrind

Could you make a PR for this? That would be really nice.

GM-Alex avatar May 17 '19 07:05 GM-Alex

fine, but I need a clarification:

RewriteCond %{REQUEST_URI} !.*\/sites\/[0-9]+\/.*

  1. what is the purpose of the rule above?
  2. why are you escaping the forward slashes?

Cheers.

bunglegrind avatar May 17 '19 08:05 bunglegrind

Created. But there may be similar issues...

bunglegrind avatar May 21 '19 10:05 bunglegrind

Yes there are...almost every time you create a path.

bunglegrind avatar Aug 26 '20 14:08 bunglegrind

http://cmljnelson.blog/2018/07/26/which-way-do-your-slashes-face/

Probably wp_normalize_path should fix the issue (at least for the paths, concerning the uris replacing DIRECTORY_SEPARATOR with '/' is the right fix)

bunglegrind avatar Aug 27 '20 10:08 bunglegrind