Skip to content

Commit a92fc9f

Browse files
committed
add multipart_uri_whitelist INI option
1 parent 63b1c52 commit a92fc9f

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

main/SAPI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ typedef struct _sapi_globals_struct {
141141
char *default_charset;
142142
HashTable *rfc1867_uploaded_files;
143143
zend_long post_max_size;
144+
char *multipart_uri_whitelist;
144145
int options;
145146
bool sapi_started;
146147
double global_request_time;

main/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ PHP_INI_BEGIN()
878878
PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL)
879879
PHP_INI_ENTRY("max_file_uploads", "20", PHP_INI_SYSTEM|PHP_INI_PERDIR, NULL)
880880
PHP_INI_ENTRY("max_multipart_body_parts", "-1", PHP_INI_SYSTEM|PHP_INI_PERDIR, NULL)
881+
STD_PHP_INI_ENTRY("multipart_uri_whitelist", NULL, PHP_INI_PERDIR, OnUpdateString, multipart_uri_whitelist, sapi_globals_struct, sapi_globals)
881882

882883
STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_SYSTEM, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals)
883884
STD_PHP_INI_BOOLEAN("allow_url_include", "0", PHP_INI_SYSTEM, OnUpdateBool, allow_url_include, php_core_globals, core_globals)

main/rfc1867.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
670670
zend_long post_max_size = REQUEST_PARSE_BODY_OPTION_GET(post_max_size, SG(post_max_size));
671671
zend_long max_input_vars = REQUEST_PARSE_BODY_OPTION_GET(max_input_vars, PG(max_input_vars));
672672
zend_long upload_max_filesize = REQUEST_PARSE_BODY_OPTION_GET(upload_max_filesize, PG(upload_max_filesize));
673+
char *multipart_uri_whitelist = SG(multipart_uri_whitelist);
673674
const zend_encoding *internal_encoding = zend_multibyte_get_internal_encoding();
674675
php_rfc1867_getword_t getword;
675676
php_rfc1867_getword_conf_t getword_conf;
@@ -694,6 +695,24 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
694695
_basename = php_ap_basename;
695696
}
696697

698+
if(multipart_uri_whitelist != NULL) {
699+
char *uri = strtok(multipart_uri_whitelist, ":");
700+
bool find = 0;
701+
702+
while (uri)
703+
{
704+
if(strcasecmp(SG(request_info).request_uri, uri) == 0) {
705+
find = 1;
706+
break;
707+
}
708+
uri = strtok(NULL, ":");
709+
}
710+
if(!find) {
711+
EMIT_WARNING_OR_ERROR("request uri %s is not allow POST multipart body", SG(request_info).request_uri);
712+
return;
713+
}
714+
}
715+
697716
if (post_max_size > 0 && SG(request_info).content_length > post_max_size) {
698717
EMIT_WARNING_OR_ERROR("POST Content-Length of " ZEND_LONG_FMT " bytes exceeds the limit of " ZEND_LONG_FMT " bytes", SG(request_info).content_length, post_max_size);
699718
return;

0 commit comments

Comments
 (0)