Browse Source

[core] add strict.post_content_length option

Change-Id: Ie9d67eceed7e957b667554925d562018a3217209
master
Stefan Bühler 2 years ago
parent
commit
bda1a90f27
4 changed files with 22 additions and 4 deletions
  1. +9
    -0
      doc/plugin_core.xml
  2. +3
    -1
      include/lighttpd/plugin_core.h
  3. +2
    -0
      src/main/plugin_core.c
  4. +8
    -3
      src/main/request.c

+ 9
- 0
doc/plugin_core.xml View File

@@ -100,6 +100,15 @@
</textile>
</description>
</option>
<option name="strict.post_content_length">
<short>require Content-Length for POST requests</short>
<default><value>true</value></default>
<description>
<textile>
Some clients don't send Content-Length for POST requests with empty body; they should send @Content-Length: 0@. When this check is enabled they'll get a @411 Length required@ error.
</textile>
</description>
</option>

<option name="static.exclude_extensions">
<short>don't deliver static files with one of the listed extensions</short>


+ 3
- 1
include/lighttpd/plugin_core.h View File

@@ -17,7 +17,9 @@ enum liCoreOptions {

LI_CORE_OPTION_ASYNC_STAT,

LI_CORE_OPTION_BUFFER_ON_DISK_REQUEST_BODY
LI_CORE_OPTION_BUFFER_ON_DISK_REQUEST_BODY,

LI_CORE_OPTION_STRICT_POST_CONTENT_LENGTH,
};

enum liCoreOptionPtrs {


+ 2
- 0
src/main/plugin_core.c View File

@@ -2079,6 +2079,8 @@ static const liPluginOption options[] = {

{ "buffer_request_body", LI_VALUE_BOOLEAN, TRUE, NULL },

{ "strict.post_content_length", LI_VALUE_BOOLEAN, TRUE, NULL },

{ NULL, 0, 0, NULL }
};



+ 8
- 3
src/main/request.c View File

@@ -1,5 +1,6 @@

#include <lighttpd/base.h>
#include <lighttpd/plugin_core.h>
#include <lighttpd/url_parser.h>

void li_request_init(liRequest *req) {
@@ -292,10 +293,14 @@ gboolean li_request_validate_header(liConnection *con) {
/* content-length or chunked encoding is required for them */
if (con->mainvr->request.content_length == -1 && !transfer_encoding_chunked) {
/* content-length is missing */
VR_ERROR(con->mainvr, "%s", "POST-request, but content-length missing -> 411");
if (_CORE_OPTION(con->mainvr, LI_CORE_OPTION_STRICT_POST_CONTENT_LENGTH).boolean) {
VR_ERROR(con->mainvr, "%s", "POST-request, but content-length missing -> 411");

bad_request(con, 411); /* Length Required */
return FALSE;
bad_request(con, 411); /* Length Required */
return FALSE;
} else {
con->mainvr->request.content_length = 0;
}
}
break;
default:


Loading…
Cancel
Save