Skip to content

Commit

Permalink
Merge branch 'pull-request/598'
Browse files Browse the repository at this point in the history
* pull-request/598:
  add clear_env option to FPM config
  • Loading branch information
tony2001 committed Feb 24, 2014
2 parents a61d7e6 + a16304f commit 29a4407
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions sapi/fpm/fpm/fpm_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ static struct ini_value_parser_s ini_fpm_pool_options[] = {
{ "chroot", &fpm_conf_set_string, WPO(chroot) },
{ "chdir", &fpm_conf_set_string, WPO(chdir) },
{ "catch_workers_output", &fpm_conf_set_boolean, WPO(catch_workers_output) },
{ "clear_env", &fpm_conf_set_boolean, WPO(clear_env) },
{ "security.limit_extensions", &fpm_conf_set_string, WPO(security_limit_extensions) },
#ifdef HAVE_APPARMOR
{ "apparmor_hat", &fpm_conf_set_string, WPO(apparmor_hat) },
Expand Down Expand Up @@ -606,6 +607,7 @@ static void *fpm_worker_pool_config_alloc() /* {{{ */
wp->config->listen_backlog = FPM_BACKLOG_DEFAULT;
wp->config->pm_process_idle_timeout = 10; /* 10s by default */
wp->config->process_priority = 64; /* 64 means unset */
wp->config->clear_env = 1;

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

for (kv = wp->config->env; kv; kv = kv->next) {
Expand Down
1 change: 1 addition & 0 deletions sapi/fpm/fpm/fpm_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct fpm_worker_pool_config_s {
char *chroot;
char *chdir;
int catch_workers_output;
int clear_env;
char *security_limit_extensions;
struct key_value_s *env;
struct key_value_s *php_admin_values;
Expand Down
4 changes: 3 additions & 1 deletion sapi/fpm/fpm/fpm_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ int fpm_env_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
fpm_env_setproctitle(title);
efree(title);

clearenv();
if (wp->config->clear_env) {
clearenv();
}

for (kv = wp->config->env; kv; kv = kv->next) {
setenv(kv->key, kv->value, 1);
Expand Down
9 changes: 9 additions & 0 deletions sapi/fpm/php-fpm.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,15 @@ pm.max_spare_servers = 3
; Default Value: no
;catch_workers_output = yes

; Clear environment in FPM workers
; Prevents arbitrary environment variables from reaching FPM worker processes
; by clearing the environment in workers before env vars specified in this
; pool configuration are added.
; Setting to "no" will make all environment variables available to PHP code
; via getenv(), $_ENV and $_SERVER.
; Default Value: yes
;clear_env = no

; Limits the extensions of the main script FPM will allow to parse. This can
; prevent configuration mistakes on the web server side. You should only limit
; FPM to .php extensions to prevent malicious users to use other extensions to
Expand Down

0 comments on commit 29a4407

Please sign in to comment.