Skip to content

Commit edb49a6

Browse files
committed
add test for _SERVER check on filter_input
1 parent a31c7b2 commit edb49a6

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

frankenphp.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ frankenphp_config frankenphp_get_config() {
6363
};
6464
}
6565

66-
bool should_filter_var = 0;
6766
__thread uintptr_t thread_index;
6867
__thread bool is_worker_thread = false;
6968
__thread zval *os_environment = NULL;
@@ -613,10 +612,8 @@ void frankenphp_register_trusted_var(zend_string *z_key, char *value,
613612
}
614613
size_t new_val_len = val_len;
615614

616-
if ((should_filter_var &&
617-
sapi_module.input_filter(PARSE_SERVER, ZSTR_VAL(z_key), &value,
618-
new_val_len, &new_val_len)) ||
619-
!should_filter_var) {
615+
if (sapi_module.input_filter(PARSE_SERVER, ZSTR_VAL(z_key), &value,
616+
new_val_len, &new_val_len)) {
620617
zval z_value;
621618
ZVAL_STRINGL_FAST(&z_value, value, new_val_len);
622619
zend_hash_update_ind(ht, z_key, &z_value);
@@ -744,10 +741,8 @@ void frankenphp_register_variable_safe(char *key, char *val, size_t val_len,
744741
val = "";
745742
}
746743
size_t new_val_len = val_len;
747-
if ((should_filter_var &&
748-
sapi_module.input_filter(PARSE_SERVER, key, &val, new_val_len,
749-
&new_val_len)) ||
750-
!should_filter_var) {
744+
if (sapi_module.input_filter(PARSE_SERVER, key, &val, new_val_len,
745+
&new_val_len)) {
751746
php_register_variable_safe(key, val, new_val_len, track_vars_array);
752747
}
753748
}
@@ -918,12 +913,6 @@ static void *php_main(void *arg) {
918913

919914
frankenphp_sapi_module.startup(&frankenphp_sapi_module);
920915

921-
/* check if a default filter is set in php.ini and only filter if
922-
* it is, this is deprecated and will be removed in PHP 9 */
923-
char *default_filter;
924-
cfg_get_string("filter.default", &default_filter);
925-
should_filter_var = default_filter != NULL;
926-
927916
go_frankenphp_main_thread_is_ready();
928917

929918
/* channel closed, shutdown gracefully */

frankenphp_test.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ func testInput(t *testing.T, opts *testOptions) {
286286
}, opts)
287287
}
288288

289-
func TestFilterInput_module(t *testing.T) { testFilterInput(t, nil) }
290-
func TestFilterInput_worker(t *testing.T) {
289+
func TestFilterInputDefault_module(t *testing.T) { testFilterInput(t, nil) }
290+
func TestFilterInputDefault_worker(t *testing.T) {
291291
testFilterInput(t, &testOptions{workerScript: "filter.php"})
292292
}
293-
func testFilterInput(t *testing.T, opts *testOptions) {
293+
func testFilterInputDefault(t *testing.T, opts *testOptions) {
294294
if opts == nil {
295295
opts = &testOptions{}
296296
}
@@ -309,6 +309,23 @@ func testFilterInput(t *testing.T, opts *testOptions) {
309309
}, opts)
310310
}
311311

312+
func TestFilterInput_module(t *testing.T) { testFilterInput(t, nil) }
313+
func TestFilterInput_worker(t *testing.T) {
314+
testFilterInput(t, &testOptions{workerScript: "filter.php"})
315+
}
316+
func testFilterInput(t *testing.T, opts *testOptions) {
317+
runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) {
318+
req := httptest.NewRequest("GET", "http://example.com/filter.php", nil)
319+
w := httptest.NewRecorder()
320+
handler(w, req)
321+
322+
resp := w.Result()
323+
body, _ := io.ReadAll(resp.Body)
324+
325+
assert.Equal(t, "GET", string(body))
326+
}, opts)
327+
}
328+
312329
func TestPostSuperGlobals_module(t *testing.T) { testPostSuperGlobals(t, nil) }
313330
func TestPostSuperGlobals_worker(t *testing.T) {
314331
testPostSuperGlobals(t, &testOptions{workerScript: "super-globals.php"})

0 commit comments

Comments
 (0)