Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 162478 - dev-lang/php: Apache2 config uses AddType when it should be AddHandler
Summary: dev-lang/php: Apache2 config uses AddType when it should be AddHandler
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: PHP Bugs
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2007-01-17 04:55 UTC by Steve L
Modified: 2009-01-11 21:29 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Use SetHandler rather than misleading AddType (70_mod_php5.conf-apache2.patch,789 bytes, patch)
2009-01-05 23:28 UTC, Jamie Learmonth
Details | Diff
70_mod_php5.conf-apache2.patch (70_mod_php5.conf-apache2.patch,865 bytes, patch)
2009-01-07 07:47 UTC, Steve L
Details | Diff
70_mod_php.conf-apache2.patch (70_mod_php.conf-apache2.patch,810 bytes, patch)
2009-01-07 07:54 UTC, Steve L
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Steve L 2007-01-17 04:55:51 UTC
According to thumbs in #apache php files are supposed to be configured via AddHandler, not AddType. I have no idea how serious this is as I was just helping another user to get some support.

[01:11] <thumbs> do NOT use AddType for php
[01:11] <fajita> PHP is enabled (see http://www.php.net) with 'AddHandler application/x-httpd-php .php .phtml' (in your httpd.conf file) or See http://www.php.net/manual/en/install.unix.apache2.php) or See http://www.php.net/manual/en/install.unix.apache.php) (disregard their use of AddType, See 'AddType')
[01:11] <thumbs> AddHandler application/x-httpd-php .php .phtml


Reproducible: Always
Comment 1 Jakub Moc (RETIRED) gentoo-dev 2007-01-17 08:09:32 UTC
Uhm, the upstream documentation you've linked here [1] explicitely uses AddType, and as it works just fine, it's not going to change. Reopen with more information if you have problems with this, meanwhile WORKSFORME.

[1] http://www.php.net/manual/en/install.unix.apache2.php)
Comment 2 Steve L 2007-01-18 19:04:54 UTC
I appreciate that the php docs explicitly use PHP that's why the #apache people said:
"disregard their use of AddType, See 'AddType'"
Honestly Jakub are you sleeping or what ;)
Sorry, know you're stressed with loads of bugs. And like I said, this isn't affecting me, so fix it, don't fix it, I don't really care. I just thought it'd be wise for gentoo to follow best practise as advised by the apache bods.
Comment 3 Jakub Moc (RETIRED) gentoo-dev 2007-01-19 08:40:35 UTC
As said, if you have problems, then post info about your problems and we'll look into it. We are not changing ebuilds which work fine just because someone on IRC told you that they are wrong for unspecified reason.
Comment 4 Steve L 2007-01-21 02:56:51 UTC
And as I have twice said, this doesn't affect me.
Are you saying that this is *not* the recommended course of action for apache software?

If so, I haven't read it in your comments, and frankly I think it a little unprofessional (not in the paid sense, mind) simply to focus on the "gentoo way" (meaning your process) rather than the quality of the software.

Kindly note that I have not once changed your supposed resolution of this issue.
Comment 5 Jakub Moc (RETIRED) gentoo-dev 2007-01-21 05:22:21 UTC
Well, if noone has a problem with this, then I fail to see the point of this bug. Switching to AddHandler would make it impossible for users to use RemoveType if they need it. 

Enough here, not changing this.
Comment 6 Steve L 2007-01-21 19:35:09 UTC
Um, according to apache folks:
mod_security will fail to see php requests as 'dynamic' is php is incorrectly configured as a type rather than a handler.

AddType is for client-side, AddHandler for the server. The use of AddType is apparently a hack that, yes, works since mod_php is coded to detect. It is not however the correct method. AddHandler is, which has been around since 1996.

To show that this isn't just "someone on IRC" please check:
http://wooga.drbacchus.com/why-we-dont-like-php
http://www.devside.net/articles/php
Comment 7 Luca Longinotti (RETIRED) gentoo-dev 2007-05-09 16:05:58 UTC
Need to take a closer look at this one.
Best regards, CHTEKK.
Comment 8 Steve L 2007-07-12 02:30:11 UTC
s/AddType/AddHandler/g

bosh! (yes; that means close this bug please, pref. RESO/FIXE ;)

(and btw there is a RemoveHandler, you grumpy..*plop*! ;P)

Comment 9 Jamie Learmonth 2009-01-05 23:27:28 UTC
The upstream documentation has been amended to reflect this recommendation. Would be a good idea to get the ebuild up to date. Posting patch.

http://uk2.php.net/manual/en/install.unix.apache2.php
Comment 10 Jamie Learmonth 2009-01-05 23:28:13 UTC
Created attachment 177518 [details, diff]
Use SetHandler rather than misleading AddType
Comment 11 Steve L 2009-01-07 07:45:43 UTC
Thanks for the patch and bump, Jamie.
> The upstream documentation has been amended to reflect this recommendation.
"Instead of only using the Apache AddType directive, we want to avoid potentially dangerous uploads and created files such as exploit.php.jpg from being executed as PHP."
CC:ing security.
Comment 12 Steve L 2009-01-07 07:47:25 UTC
Created attachment 177638 [details, diff]
70_mod_php5.conf-apache2.patch

I think it'd be cleaner if it used mime.c where possible, so we don't force the regex search when we have mime handling loaded. See attached for php4 and 5 (untested, I haven't run apache for _ages_)
Comment 13 Steve L 2009-01-07 07:50:15 UTC
Crikey, there's a _tonne_ of people watching security (doh!) so removing. Sorry for spam people.
Comment 14 Steve L 2009-01-07 07:54:44 UTC
Created attachment 177648 [details, diff]
70_mod_php.conf-apache2.patch

for PHP4; perhaps we should be thinking about changing the name to 70_mod_php4.conf-apache2 and taking the 5 off the newer one? Not sure how tricky that is.
Comment 15 Jamie Learmonth 2009-01-07 10:34:29 UTC
php 4 is out of the tree, so that conf should perhaps be removed altogether. 

Comment 16 Robert Buchholz (RETIRED) gentoo-dev 2009-01-07 12:15:48 UTC
Please keep security@ in CC if you suspect a security issue. The people watching the alias have decided to do so themselves and are used to some amount of bugmail.

Regarding the issue: Can you elaborate how AddType opens a security issue whereas AddHandler does not? Reading the mod_mime documentation, I understand that both allow for multiple filename extensions and will prefer the one associated with a handler.

Regarding the patch in attachment 177648 [details, diff]: The regular expression "\.ph(p[3-6]?|html)$" matches .phhtml instead of .phtml, which is probably not intended.
Comment 17 Robert Buchholz (RETIRED) gentoo-dev 2009-01-07 12:31:31 UTC
I could reproduce this result:
Using AddType:
* moo.php.gif        is not executed
* moo.php.something  is executed

Using AddHandler
* moo.php.gif        is executed
* moo.php.something  is executed

What am I missing here? The PHP documentation claims the opposite.
Comment 18 Jamie Learmonth 2009-01-07 13:30:44 UTC
Comment on attachment 177518 [details, diff]
Use SetHandler rather than misleading AddType

><HTML><HEAD/><BODY><PRE>--- /usr/portage/dev-lang/php/files/70_mod_php5.conf-apache2	2008-01-31 16:35:34.000000000 +0000
>+++ /usr/local/portage/dev-lang/php/files/70_mod_php5.conf-apache2	2009-01-05 23:19:17.000000000 +0000
>@@ -5,14 +5,13 @@
> 	&lt;/IfModule&gt;
> 
> 	# Set it to handle the files
>-	&lt;IfModule mod_mime.c&gt;
>-		AddType application/x-httpd-php .php
>-		AddType application/x-httpd-php .phtml
>-		AddType application/x-httpd-php .php3
>-		AddType application/x-httpd-php .php4
>-		AddType application/x-httpd-php .php5
>-		AddType application/x-httpd-php-source .phps
>-	&lt;/IfModule&gt;
>+	&lt;FilesMatch "\.ph(p[2-6]?|tml)$"&gt;
>+		SetHandler application/x-httpd-php
>+	&lt;/FilesMatch&gt; 
>+
>+	&lt;FilesMatch "\.phps"&gt;
>+		SetHandler application/x-httpd-php-source
>+	&lt;/FilesMatch&gt;
> 
> 	DirectoryIndex index.php index.phtml
> &lt;/IfDefine&gt;
></PRE></BODY></HTML>
Comment 19 Jamie Learmonth 2009-01-07 13:31:21 UTC
> Using AddType:
> * moo.php.gif        is not executed 

Perhaps mime module is kicking in choosing .gif so not executing.

> 
> What am I missing here? The PHP documentation claims the opposite.
> 

They should all execute, AddHandler is just more correct.

I am not sure why security is CC'ed in, however I support there is potential risk of php getting executed on certain file uploads because the file extension does not get fully checked (as you proved with .php.something executing) .

The patch checks the extension properly.
Comment 20 Jamie Learmonth 2009-01-07 13:34:28 UTC
Also, you are correct with the regex ... it should be:

<FilesMatch "\.ph(p[2-6]?|tml)$">

(Bugzilla edit file didn't seem to work so well)
Comment 21 Robert Buchholz (RETIRED) gentoo-dev 2009-01-07 15:29:11 UTC
As you pointed out as well, neither of the two Add* commands provides any protection from attackers who can upload files to your web server. The only protection is sanitizing/generating the file name or removing Handlers (and Types, whatever you introduced) via .htaccess -- a lack of both of these would be considered a security issue in the application that allows those file uploads.

I can agree with the design POV of using AddHandler instead of AddType, but I have no clue as to why PHP upstream claims a security impact.
Comment 22 Christian Hoffmann (RETIRED) gentoo-dev 2009-01-11 21:29:41 UTC
Thanks to all of the commenters. I have added an improved config in php-5.2.8-r2.
We're mainly using the example from upstream with <FilesMatch>, but with an adapted regexp (I don't want to cause behavior changes just by changing the configs).
Stabling is handled in bug 249703.

As to the security impact: I don't consider this to be an issue in PHP, but it's certainly a less than optimal default currently, which should be better with -r2 now. The regexp matching should ensure that only files ending with .php (and .php5, .phtml) are indeed handled by PHP, and not arbitrary files, which just accidently happen to contain a ".php" somewhere in the name.