Last modified: 2014-05-27 10:48:40 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T67220, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 65220 - images/.htaccess breaks TransformVia404 functionality
images/.htaccess breaks TransformVia404 functionality
Status: PATCH_TO_REVIEW
Product: MediaWiki
Classification: Unclassified
File management (Other open bugs)
1.23.0
All All
: Normal normal with 1 vote (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-05-12 11:57 UTC by forwardin
Modified: 2014-05-27 10:48 UTC (History)
7 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description forwardin 2014-05-12 11:57:01 UTC
I have enabled TransformVia404 by $wgGenerateThumbnailOnParse = false; and it's works, BUT without images/.htaccess. With images/.htaccess new images return 404 Not Found, but previously generated images (via TransformVia404) work!

Description:	Ubuntu 12.04.4 LTS
Server version: Apache/2.2.22 (Ubuntu)
Server built:   Mar 19 2014 21:11:10

Contents of file:

# Protect against bug 28235
<IfModule rewrite_module>
        RewriteEngine On
        RewriteCond %{QUERY_STRING} \.[^\\/:*?\x22<>|%]+(#|\?|$) [nocase]
        RewriteRule . - [forbidden]
</IfModule>

I'm not so good in mod_rewrite so don't know what actually wrong.

I'm also tried to delete from /.htaccess all rules except required for TransformVia404 with no success:

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l
RewriteRule ^images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/[^/]+/[^/]+$ /thumb_handler.php [L,QSA]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l
RewriteRule ^images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/[^/]+/[^/]+$ /thumb_handler.php [L,QSA]
Comment 1 forwardin 2014-05-12 12:22:28 UTC
Changed to:

# Protect against bug 28235
<IfModule rewrite_module>
	RewriteEngine On
	RewriteCond %{DOCUMENT_ROOT}%{QUERY_STRING} \.[^\\/:*?\x22<>|%]+(#|\?|$) [nocase]
	RewriteRule . - [forbidden]
</IfModule>

Now new images return 403 Forbidden.
Comment 2 forwardin 2014-05-12 12:44:18 UTC
(In reply to forwardin from comment #1)
> Changed to:
> 
> # Protect against bug 28235
> <IfModule rewrite_module>
> 	RewriteEngine On
> 	RewriteCond %{DOCUMENT_ROOT}%{QUERY_STRING} \.[^\\/:*?\x22<>|%]+(#|\?|$)
> [nocase]
> 	RewriteRule . - [forbidden]
> </IfModule>
> 
> Now new images return 403 Forbidden.

Correction: looks like 403 Forbidden on all images. So without %{DOCUMENT_ROOT} this .htaccess working strange for me. But with he works and redirects all images to 403 Forbidden. :(
Comment 3 Tisza Gergő 2014-05-12 17:38:34 UTC
mediawiki-vagrant with the multimedia role enabled uses 404 transforms, you compare it to your own setup and find out what's being done differently.
Comment 4 forwardin 2014-05-12 17:59:14 UTC
With this work:

RewriteEngine On

RewriteCond %{QUERY_STRING} \.[^\\/:*?\x22<>|%]+(#|\?|$) [nocase]
RewriteRule . - [forbidden]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l
RewriteRule ^thumb/[0-9a-f]/[0-9a-f][0-9a-f]/[^/]+/[^/]+$ /thumb_handler.php [L,QSA]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l
RewriteRule ^thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/[^/]+/[^/]+$ /thumb_handler.php [L,QSA]


/images/thumb/7/7d/111.jpg?.fdfdf - 403 Forbidden
/images/thumb/7/7d/111.jpg - 200 Ok

Looks like if in subfolder exists .htaccess then .htaccess in parent folder ignored.

From http://www.helicontech.com/forum/13329-htaccess_rootchild_not_working.html:

Now I understand the problem. This is by design behavior we implemented exactly as it is in Apache. Lower .htaccess files completely owerride upper configurations unless you put "RewriteOptions inherit" into it. If no .htaccess specified, the closest upper one will be executed. Also Apache always executes httpd.conf file. This behavor can be changed of caurse, but we will loose Apache compatibility then.
Also if inherit options is used it means that all directives will be moved into this file from the upper file and will be applied in the context of the lower file. This is also Apache behavior.
So if you write .htaccess and want include rules from upper file you need to use inherit option. If no .htaccess file exists, your upper rules will be applied.
Comment 5 forwardin 2014-05-12 18:15:26 UTC
I found solution:

# Protect against bug 28235
<IfModule rewrite_module>
	RewriteEngine On
	RewriteOptions inherit
	RewriteCond %{QUERY_STRING} \.[^\\/:*?\x22<>|%]+(#|\?|$) [nocase]
	RewriteRule . - [forbidden]
</IfModule>

RewriteOptions inherit - with this option parent /.htaccess will be executed after /images/.htaccess, BUT you need to change in parent path (delete "images/"):

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l
RewriteRule ^thumb/[0-9a-f]/[0-9a-f][0-9a-f]/[^/]+/[^/]+$ /thumb_handler.php [L,QSA]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l
RewriteRule ^thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/[^/]+/[^/]+$ /thumb_handler.php [L,QSA]
Comment 6 Gerrit Notification Bot 2014-05-12 18:41:18 UTC
Change 132971 had a related patch set uploaded by Scnd:
Bug 65220

https://gerrit.wikimedia.org/r/132971
Comment 7 Gerrit Notification Bot 2014-05-12 18:49:51 UTC
Change 132971 abandoned by Scnd:
Bug 65220

Reason:
Bad formatting.

https://gerrit.wikimedia.org/r/132971
Comment 8 Gerrit Notification Bot 2014-05-12 18:55:09 UTC
Change 132974 had a related patch set uploaded by Scnd:
Bug 65220

https://gerrit.wikimedia.org/r/132974
Comment 9 Tisza Gergő 2014-05-12 21:17:28 UTC
I am not sure I understand what's the actual bug here. Does the lack of rewrite rule inheritance break 404 handlers on a vagrant box with multimedia role enabled? On a clean MediaWiki install? On a specific site?

Could you provide a step-by-step description with expected and actual outcomes?

(Side note: you can update gerrit patches by using git commit --amend, you don't need to create a new patchset to fix errors in the old one. See https://www.mediawiki.org/wiki/Gerrit/Tutorial#Amending_a_change )
Comment 10 forwardin 2014-05-13 14:49:41 UTC
(In reply to Tisza Gergő from comment #9)
> I am not sure I understand what's the actual bug here. Does the lack of
> rewrite rule inheritance break 404 handlers on a vagrant box with multimedia
> role enabled? On a clean MediaWiki install? On a specific site?
> 
> Could you provide a step-by-step description with expected and actual
> outcomes?
> 
> (Side note: you can update gerrit patches by using git commit --amend, you
> don't need to create a new patchset to fix errors in the old one. See
> https://www.mediawiki.org/wiki/Gerrit/Tutorial#Amending_a_change )

This vagrant box uses server files /etc/apache2/site.d/devwiki/000-devwiki:

RewriteEngine On
RewriteRule ^/$ /w/index.php [R=301]

Alias /wiki "/vagrant/mediawiki/index.php"
Alias /w "/vagrant/mediawiki"
Alias /images "/srv/images"
Alias /mediawiki-vagrant.png /var/www/mediawiki-vagrant.png
Alias /favicon.ico /var/www/favicon.ico

/etc/apache2/site.d/devwiki/thumb-php-on-404:

RewriteEngine On

# call thumb.php for thumb images not on disk
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/[^/]*([0-9]+)px-.*$ /w/thumb_handler.php [PT,QSA,B]


# call thumb.php for thumb archive images not on disk
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/[^/]*([0-9]+)px-.*$ /w/thumb_handler.php [PT,QSA,B]


That is terrible for test environment.
Comment 11 Tisza Gergő 2014-05-13 17:38:22 UTC
So, if I understand correctly, the steps to reproduce are:

1. start with a standard MediaWiki setup
2. set $wgGenerateThumbnailOnParse = false;
3. create a .htaccess file in the MediaWiki root directory
4. copy these rules into it:
       RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
       RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
       RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l
       RewriteRule ^images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/[^/]+/[^/]+$ /thumb_handler.php [L,QSA]

       RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
       RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
       RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l
       RewriteRule ^images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/[^/]+/[^/]+$ /thumb_handler.php [L,QSA]

...and images will break because these rules are disabled by the lower-level .htaccess file. Is this correct?
Comment 12 forwardin 2014-05-13 17:53:37 UTC
Also

	RewriteEngine on

And disabled will be all contents of all high-level .htaccess files. Other correct.
Comment 13 Andre Klapper 2014-05-16 12:40:12 UTC
(In reply to Gerrit Notification Bot from comment #8)
> Change 132974 had a related patch set uploaded by Scnd:
> Bug 65220
> 
> https://gerrit.wikimedia.org/r/132974

For the records, this is for 1.23 only.
Comment 14 Gerrit Notification Bot 2014-05-27 10:48:40 UTC
Change 135543 had a related patch set uploaded by Krinkle:
images/.htaccess breaks TransformVia404 functionality

https://gerrit.wikimedia.org/r/135543

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links