Skip to content

Commit 29a4407

Browse files
committed
Merge branch 'pull-request/598'
* pull-request/598: add clear_env option to FPM config
2 parents a61d7e6 + a16304f commit 29a4407

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

sapi/fpm/fpm/fpm_conf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ static struct ini_value_parser_s ini_fpm_pool_options[] = {
148148
{ "chroot", &fpm_conf_set_string, WPO(chroot) },
149149
{ "chdir", &fpm_conf_set_string, WPO(chdir) },
150150
{ "catch_workers_output", &fpm_conf_set_boolean, WPO(catch_workers_output) },
151+
{ "clear_env", &fpm_conf_set_boolean, WPO(clear_env) },
151152
{ "security.limit_extensions", &fpm_conf_set_string, WPO(security_limit_extensions) },
152153
#ifdef HAVE_APPARMOR
153154
{ "apparmor_hat", &fpm_conf_set_string, WPO(apparmor_hat) },
@@ -606,6 +607,7 @@ static void *fpm_worker_pool_config_alloc() /* {{{ */
606607
wp->config->listen_backlog = FPM_BACKLOG_DEFAULT;
607608
wp->config->pm_process_idle_timeout = 10; /* 10s by default */
608609
wp->config->process_priority = 64; /* 64 means unset */
610+
wp->config->clear_env = 1;
609611

610612
if (!fpm_worker_all_pools) {
611613
fpm_worker_all_pools = wp;
@@ -1606,6 +1608,7 @@ static void fpm_conf_dump() /* {{{ */
16061608
zlog(ZLOG_NOTICE, "\tchroot = %s", STR2STR(wp->config->chroot));
16071609
zlog(ZLOG_NOTICE, "\tchdir = %s", STR2STR(wp->config->chdir));
16081610
zlog(ZLOG_NOTICE, "\tcatch_workers_output = %s", BOOL2STR(wp->config->catch_workers_output));
1611+
zlog(ZLOG_NOTICE, "\tclear_env = %s", BOOL2STR(wp->config->clear_env));
16091612
zlog(ZLOG_NOTICE, "\tsecurity.limit_extensions = %s", wp->config->security_limit_extensions);
16101613

16111614
for (kv = wp->config->env; kv; kv = kv->next) {

sapi/fpm/fpm/fpm_conf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct fpm_worker_pool_config_s {
8383
char *chroot;
8484
char *chdir;
8585
int catch_workers_output;
86+
int clear_env;
8687
char *security_limit_extensions;
8788
struct key_value_s *env;
8889
struct key_value_s *php_admin_values;

sapi/fpm/fpm/fpm_env.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ int fpm_env_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
143143
fpm_env_setproctitle(title);
144144
efree(title);
145145

146-
clearenv();
146+
if (wp->config->clear_env) {
147+
clearenv();
148+
}
147149

148150
for (kv = wp->config->env; kv; kv = kv->next) {
149151
setenv(kv->key, kv->value, 1);

sapi/fpm/php-fpm.conf.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,15 @@ pm.max_spare_servers = 3
475475
; Default Value: no
476476
;catch_workers_output = yes
477477

478+
; Clear environment in FPM workers
479+
; Prevents arbitrary environment variables from reaching FPM worker processes
480+
; by clearing the environment in workers before env vars specified in this
481+
; pool configuration are added.
482+
; Setting to "no" will make all environment variables available to PHP code
483+
; via getenv(), $_ENV and $_SERVER.
484+
; Default Value: yes
485+
;clear_env = no
486+
478487
; Limits the extensions of the main script FPM will allow to parse. This can
479488
; prevent configuration mistakes on the web server side. You should only limit
480489
; FPM to .php extensions to prevent malicious users to use other extensions to

0 commit comments

Comments
 (0)