Skip to content

Commit b4748ee

Browse files
fix: don’t ignore empty request headers (#1182)
* Fixes empty request headers. * Formatting
1 parent b40c5a6 commit b4748ee

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

caddy/caddy_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ func TestAllDefinedServerVars(t *testing.T) {
607607
"Content-Length: 14", // maliciously set to 14
608608
"Special-Chars: <%00>",
609609
"Host: Malicous Host",
610+
"X-Empty-Header:",
610611
},
611612
bytes.NewBufferString("foo=bar"),
612613
http.StatusOK,

frankenphp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,12 @@ void frankenphp_register_variables_from_request_info(
707707
* see: php_variables.c -> php_register_variable_ex (#1106) */
708708
void frankenphp_register_variable_safe(char *key, char *val, size_t val_len,
709709
zval *track_vars_array) {
710-
if (val == NULL || key == NULL) {
710+
if (key == NULL) {
711711
return;
712712
}
713+
if (val == NULL) {
714+
val = "";
715+
}
713716
size_t new_val_len = val_len;
714717
if (!should_filter_var ||
715718
sapi_module.input_filter(PARSE_SERVER, key, &val, new_val_len,

frankenphp_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -952,13 +952,10 @@ func FuzzRequest(f *testing.F) {
952952
assert.Contains(t, string(body), fmt.Sprintf("[PATH_INFO] => /%s", fuzzedString))
953953
assert.Contains(t, string(body), fmt.Sprintf("[PATH_TRANSLATED] => %s", filepath.Join(absPath, fuzzedString)))
954954

955-
// The header should only be present if the fuzzed string is not empty
956-
if len(fuzzedString) > 0 {
957-
assert.Contains(t, string(body), fmt.Sprintf("[CONTENT_TYPE] => %s", fuzzedString))
958-
assert.Contains(t, string(body), fmt.Sprintf("[HTTP_FUZZED] => %s", fuzzedString))
959-
} else {
960-
assert.NotContains(t, string(body), "[HTTP_FUZZED]")
961-
}
955+
// Headers should always be present even if empty
956+
assert.Contains(t, string(body), fmt.Sprintf("[CONTENT_TYPE] => %s", fuzzedString))
957+
assert.Contains(t, string(body), fmt.Sprintf("[HTTP_FUZZED] => %s", fuzzedString))
958+
962959
}, &testOptions{workerScript: "request-headers.php"})
963960
})
964961
}

testdata/server-all-vars-ordered.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'REMOTE_USER',
3434
'REQUEST_METHOD',
3535
'REQUEST_URI',
36+
'HTTP_X_EMPTY_HEADER',
3637
] as $name) {
3738
echo "$name:" . $_SERVER[$name] . "\n";
3839
}

testdata/server-all-vars-ordered.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ QUERY_STRING:specialChars=%3E\x00%00</>
3030
REMOTE_USER:user
3131
REQUEST_METHOD:POST
3232
REQUEST_URI:/server-all-vars-ordered.php/path?specialChars=%3E\x00%00</>
33+
HTTP_X_EMPTY_HEADER:
3334
</pre>

0 commit comments

Comments
 (0)