From phil@philpep.org  Wed Jan 27 23:20:24 2010
Return-Path: <phil@philpep.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 4D73C106568B
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 27 Jan 2010 23:20:24 +0000 (UTC)
	(envelope-from phil@philpep.org)
Received: from squat.philpep.org (squat.philpep.org [82.229.137.130])
	by mx1.freebsd.org (Postfix) with ESMTP id 0A79F8FC16
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 27 Jan 2010 23:20:23 +0000 (UTC)
Received: from shen.philpep.org (shen.philpep.org [192.168.0.2])
	by trotski.philpep.org (Postfix) with SMTP id 38375AC810
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 28 Jan 2010 00:19:17 +0100 (CET)
Received: by shen.philpep.org (sSMTP sendmail emulation); Thu, 28 Jan 2010 00:16:56 +0100
Message-Id: <20100127232024.4D73C106568B@hub.freebsd.org>
Date: Thu, 28 Jan 2010 00:16:56 +0100
From: "Philippe Pepiot" <phil@philpep.org>
Reply-To: Philippe Pepiot <phil@philpep.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Update port www/lighttpd: start with clean environment
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         143302
>Category:       ports
>Synopsis:       Update port www/lighttpd: start with clean environment
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mm
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 27 23:30:01 UTC 2010
>Closed-Date:    Mon Sep 06 12:20:59 UTC 2010
>Last-Modified:  Mon Sep 06 12:20:59 UTC 2010
>Originator:     Philippe Pepiot
>Release:        FreeBSD 8.0-RELEASE-p2 i386
>Organization:
>Environment:
System: FreeBSD shen.philpep.org 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #0 r202418: Fri Jan 15 22:29:53 CET 2010 root@shen.philpep.org:/usr/obj/usr/src/sys/SHEN i386


	
>Description:
	Lighttpd start with environment from parent process. With this patch
	lighttpd can start with clean (or controlled) environment. For example
	if your cgi script need $PATH, just set lighttpd_allowed_env="PATH" on your
	/etc/rc.conf file.
	For security reason, It's not a good idea to put root user environment into
	lighttpd process.
>How-To-Repeat:
	
>Fix:

	

--- www_lighttpd.patch begins here ---
diff -ru lighttpd.orig/files/lighttpd.sh.in lighttpd/files/lighttpd.sh.in
--- lighttpd.orig/files/lighttpd.sh.in	2010-01-27 23:55:24.000000000 +0100
+++ lighttpd/files/lighttpd.sh.in	2010-01-27 23:56:09.000000000 +0100
@@ -26,6 +26,7 @@
 : ${lighttpd_enable="NO"}
 : ${lighttpd_conf="%%PREFIX%%/etc/lighttpd.conf"}
 : ${lighttpd_pidfile="/var/run/${name}.pid"}
+: ${lighttpd_allowed_env=""}
 
 command=%%PREFIX%%/sbin/lighttpd
 command_args="-f ${lighttpd_conf}"
@@ -39,6 +40,21 @@
 check_cmd="checkconfig"
 extra_commands="reload check"
 
+start_precmd="${name}_start_precmd"
+
+lighttpd_start_precmd()
+{
+    E=
+    for i in ${lighttpd_allowed_env}; do
+        eval _val="\$$i"
+        if [ "${_val}_x" != "_x" ]; then
+            eval _add="$i=$_val"
+            E="${E} ${_add}"
+        fi
+    done
+    command="env - ${E} ${command}"
+}
+
 checkconfig()
 {
 	echo "Performing sanity check on ${name} configuration:"
--- www_lighttpd.patch ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->mnag 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Wed Jan 27 23:30:14 UTC 2010 
Responsible-Changed-Why:  
Over to maintainer (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=143302 
Responsible-Changed-From-To: mnag->mm 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Aug 3 01:11:58 UTC 2010 
Responsible-Changed-Why:  
Over to new maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=143302 

From: Martin Matuska <mm@FreeBSD.org>
To: bug-followup@FreeBSD.org, phil@philpep.org
Cc:  
Subject: Re: ports/143302: Update port www/lighttpd: start with clean environment
Date: Tue, 03 Aug 2010 19:56:39 +0200

 Why is this needed? I don't see a reson.
 
 CGI scripts are run under a different environment.
 You can modify this environment with mod_setenv.

From: Philippe Pepiot <phil@philpep.org>
To: Martin Matuska <mm@FreeBSD.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/143302: Update port www/lighttpd: start with clean
 environment
Date: Thu, 5 Aug 2010 02:08:39 +0200

 This is needed because :
 
 # setenv SECRET_ENV_KEY SECRET_ENV_VALUE
 # /usr/local/etc/rc.d/lighttpd restart
 
 And (imagine your are hosting people), SECRET_ENV_VALUE is availiable
 in cgi environmement.
 
 mod_setenv can just add or overwrite environment, it's better to clean
 env _before_ starting cgi. Apache do that, but not lighttpd.
 
 See http://redmine.lighttpd.net/issues/1891 they say this is the rc
 script job. We can set lighttpd_allowed_env="LD_LIBRARY_PATH PATH ..."
 on default env.
 
 Ok it's stupid to store confidential data into env, but you probably
 dont show SSH_CONNECTION or somethink like that.
 
 
 On Tue, Aug 03, 2010 at 07:56:39PM +0200, Martin Matuska wrote:
 > Why is this needed? I don't see a reson.
 > 
 > CGI scripts are run under a different environment.
 > You can modify this environment with mod_setenv.
 

From: Martin Matuska <mm@FreeBSD.org>
To: bug-followup@FreeBSD.org, phil@philpep.org
Cc:  
Subject: Re: ports/143302: Update port www/lighttpd: start with clean environment
Date: Thu, 05 Aug 2010 08:36:33 +0200

 Have you tried to reproduce that?
 
 I have created a "test.sh" script with the following contents:
 
 #!/bin/sh
 echo Content-type: text/plain
 echo
 printenv
 
 In lighttpd.conf, set:
 cgi.assign                  = ( ".sh" => "/bin/sh" )
 
 I set any custom environment variables and restart lighttpd via rc
 script. The output of the script via CGI interface does not show up any
 custom environment variables.
 
 Why? I have examined the src/mod_cgi.c and src/mod_scgi.c code and the
 environment is cleaned and re-created with CGI/FastCGI defaults before
 scripts are run.
State-Changed-From-To: open->closed 
State-Changed-By: mm 
State-Changed-When: Mon Sep 6 12:20:57 UTC 2010 
State-Changed-Why:  
Closing on submitter feedback timeout. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=143302 
>Unformatted:
