diff --git a/frankenphp.c b/frankenphp.c index a9cd534dc5..6592852dda 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -63,7 +63,6 @@ frankenphp_config frankenphp_get_config() { }; } -bool should_filter_var = 0; __thread uintptr_t thread_index; __thread bool is_worker_thread = false; __thread zval *os_environment = NULL; @@ -613,8 +612,7 @@ void frankenphp_register_trusted_var(zend_string *z_key, char *value, } size_t new_val_len = val_len; - if (!should_filter_var || - sapi_module.input_filter(PARSE_SERVER, ZSTR_VAL(z_key), &value, + if (sapi_module.input_filter(PARSE_SERVER, ZSTR_VAL(z_key), &value, new_val_len, &new_val_len)) { zval z_value; ZVAL_STRINGL_FAST(&z_value, value, new_val_len); @@ -743,8 +741,7 @@ void frankenphp_register_variable_safe(char *key, char *val, size_t val_len, val = ""; } size_t new_val_len = val_len; - if (!should_filter_var || - sapi_module.input_filter(PARSE_SERVER, key, &val, new_val_len, + if (sapi_module.input_filter(PARSE_SERVER, key, &val, new_val_len, &new_val_len)) { php_register_variable_safe(key, val, new_val_len, track_vars_array); } @@ -916,12 +913,6 @@ static void *php_main(void *arg) { frankenphp_sapi_module.startup(&frankenphp_sapi_module); - /* check if a default filter is set in php.ini and only filter if - * it is, this is deprecated and will be removed in PHP 9 */ - char *default_filter; - cfg_get_string("filter.default", &default_filter); - should_filter_var = default_filter != NULL; - go_frankenphp_main_thread_is_ready(); /* channel closed, shutdown gracefully */ diff --git a/frankenphp_test.go b/frankenphp_test.go index 2df44ebfc5..54c7043305 100644 --- a/frankenphp_test.go +++ b/frankenphp_test.go @@ -286,6 +286,46 @@ func testInput(t *testing.T, opts *testOptions) { }, opts) } +func TestFilterInputDefault_module(t *testing.T) { testFilterInputDefault(t, nil) } +func TestFilterInputDefault_worker(t *testing.T) { + testFilterInputDefault(t, &testOptions{workerScript: "filter.php"}) +} +func testFilterInputDefault(t *testing.T, opts *testOptions) { + if opts == nil { + opts = &testOptions{} + } + opts.initOpts = append(opts.initOpts, frankenphp.WithPhpIni(map[string]string{ + "filter.default": "string.tolower", + })) + runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) { + req := httptest.NewRequest("GET", "http://example.com/filter.php", nil) + w := httptest.NewRecorder() + handler(w, req) + + resp := w.Result() + body, _ := io.ReadAll(resp.Body) + + assert.Equal(t, "GET", string(body)) + }, opts) +} + +func TestFilterInput_module(t *testing.T) { testFilterInput(t, nil) } +func TestFilterInput_worker(t *testing.T) { + testFilterInput(t, &testOptions{workerScript: "filter.php"}) +} +func testFilterInput(t *testing.T, opts *testOptions) { + runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) { + req := httptest.NewRequest("GET", "http://example.com/filter.php", nil) + w := httptest.NewRecorder() + handler(w, req) + + resp := w.Result() + body, _ := io.ReadAll(resp.Body) + + assert.Equal(t, "GET", string(body)) + }, opts) +} + func TestPostSuperGlobals_module(t *testing.T) { testPostSuperGlobals(t, nil) } func TestPostSuperGlobals_worker(t *testing.T) { testPostSuperGlobals(t, &testOptions{workerScript: "super-globals.php"}) diff --git a/testdata/filter.php b/testdata/filter.php new file mode 100644 index 0000000000..b8e1d41701 --- /dev/null +++ b/testdata/filter.php @@ -0,0 +1,6 @@ +