You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Dominique Quatravaux <do...@idealx.com> on 2001/07/17 20:23:38 UTC

[BUG] $r->subprocess_env() leaking to %ENV

Hello,

I found the following behaviour in mod_perl, which is clearly
unexpected: I use an Apache that can serve both mod_perl and PHP
pages. I run it -X ; first I request the URI for this scriptlet
(under mod_perl's Apache::Registry):

#!/usr/bin/perl
$ENV{"LEAKING"}="oops";

Then I visit a PHP page that contains just phpinfo() - the LEAKING
variable is passed to it, I can see it in the HTTP_ENV_VARS.

So far, so good - a remanent environment may not be what I want, but
it certainly is not a bug. It becomes worse with a module that sets
things in the CGI namespace ($r->subprocess_env()), such as mod_ssl :
if I request the Perl scriptlet through SSL, all variables in the
subprocess_env (HTTPS, SERVER_CERTIFICATE et al., that normally show
up as HTTP_SERVER_VARS in phpinfo()) are somehow promoted as
environment variables, and become remanent in the server process
environment as shown above (i.e. they now appear as HTTP_ENV_VARS for
subsequent requests). This seems to happen at the time the first (I
didn't test more) request to an Apache::Registry script is made in the
life of an httpd : requesting phpinfo() pages beforehand doesn't
show any spurious environment data, even through SSL.

Using a debugger shows (as expected from %ENV modifications) that the
real environment (char **__environ) is modified in both scenari, so
this is not due to a bug in PHP.

I ended up writing a cleanup handler that restores %ENV to what it was
at server startup time, and everything works fine now.

Platform: RH 7.1, mod_perl 1.24_01, Apache 1.3.19, PHP 4.0.4pl1.

Sorry I cannot investigate any further by myself, because I know next
to nothing in XS and mod_perl uses it heavily. I just saw that %ENV is
tied by C code, but I hear it is related to tainting and I don't see how
this could cause the observed behaviour.

-- 
<< Tout n'y est pas parfait, mais on y honore certainement les jardiniers >>

			Dominique Quatravaux <do...@kilimandjaro.dyndns.org>

Re: [BUG] $r->subprocess_env() leaking to %ENV

Posted by Dominique Quatravaux <do...@idealx.com>.
> Can't all these modules (your scripts, 

 The environment leak in my test case was just to make my point clear,
not a programmatic example of course

> mod_ssl, etc) just use the request object and/or Apache notes to
> communicate?  That's exactly what they're there for!

  I get it now: there is a kind of lost-update (actually, lost-delete)
problem because both mod_ssl and mod_perl try to write into the
environment, and cleanup in the wrong sequence (update 1-update
2-cleanup 1-cleanup 2). Thank you for helping me pointing it out.

> At least mod_perl can be told not to mess with the environment:
> 
> <Directory /my/modperl/webroot>
>   PerlSetupEnv Off
> </Directory>

  Well sure, I even tried it but I use CGI.pm from Perl 5.6 and 

CGI.pm>     $meth=$ENV{'REQUEST_METHOD'} if defined($ENV{'REQUEST_METHOD'});
CGI.pm> [...]
CGI.pm>     # If $meth is not of GET, POST or HEAD, assume we're being debugged offline.

  And there comes a funny message in my error log telling me
to enter name=value pairs on the standard input :-) 

  Your proposition, however righteous, means a lot of work for a lot
of people... Or perhaps Apache::Registry::handler should do some
tie()ing ? (yuck)

  In the meantime, I will be cutting the StdEnvVars off from mod_ssl
configuration. Thanks again !

-- 
<< Tout n'y est pas parfait, mais on y honore certainement les jardiniers >>

			Dominique Quatravaux <do...@kilimandjaro.dyndns.org>

Re: [BUG] $r->subprocess_env() leaking to %ENV

Posted by Roger Espel Llima <ro...@iagora.net>.
Dominique Quatravaux <do...@idealx.com> wrote:
> I found the following behaviour in mod_perl, which is clearly
> unexpected: I use an Apache that can serve both mod_perl and PHP
> pages. I run it -X ; first I request the URI for this scriptlet
> (under mod_perl's Apache::Registry):
> 
> #!/usr/bin/perl
> $ENV{"LEAKING"}="oops";
> 
> Then I visit a PHP page that contains just phpinfo() - the LEAKING
> variable is passed to it, I can see it in the HTTP_ENV_VARS.

The whole idea of using the environemnt for communication within a
single process seems quite wrong to me.

Can't all these modules (your scripts, mod_ssl, etc) just use the
request object and/or Apache notes to communicate?  That's exactly
what they're there for!

At least mod_perl can be told not to mess with the environment:

<Directory /my/modperl/webroot>
  PerlSetupEnv Off
</Directory>

-- 
Roger Espel Llima, roger@iagora.net
http://www.iagora.com/~espel/index.html