diff --git a/README b/README index 3586630..12d65a2 100644 --- a/README +++ b/README @@ -15,7 +15,7 @@ Limitations Currently only inspects the following headers: Range, If-Range, If-Unmodified-Since, If-Modified-Since, Date, Accept-Encoding, - Accept-Language, Accept-Charset + Accept-Language, Accept-Charset, Max-Forwards Report Bugs Create a ticket on the issue tracking interface of GitHub: diff --git a/ngx_http_header_inspect.c b/ngx_http_header_inspect.c index 10ba387..4fd13aa 100644 --- a/ngx_http_header_inspect.c +++ b/ngx_http_header_inspect.c @@ -29,6 +29,7 @@ static ngx_int_t ngx_header_inspect_acceptencoding_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); static ngx_int_t ngx_header_inspect_acceptlanguage_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); static ngx_int_t ngx_header_inspect_acceptcharset_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); +static ngx_int_t ngx_header_inspect_maxforwards_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); static ngx_int_t ngx_header_inspect_ifrange_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); static ngx_int_t ngx_header_inspect_date_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, char *header, ngx_str_t value); static ngx_int_t ngx_header_inspect_process_request(ngx_http_request_t *r); @@ -866,6 +867,24 @@ } } +static ngx_int_t ngx_header_inspect_maxforwards_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value) { + ngx_uint_t i = 0; + + if ( value.len <= 0 ) { + ngx_log_error(NGX_LOG_ALERT, log, 0, "header_inspect: Max-Forwards header \"%s\" is empty", value.data); + return NGX_ERROR; + } + + for ( i = 0; i < value.len; i++ ) { + if ( (value.data[i] < '0') || (value.data[i] > '9') ) { + ngx_log_error(NGX_LOG_ALERT, log, 0, "header_inspect: invalid digit at position %d in Max-Forwards header \"%s\"", i, value.data); + return NGX_ERROR; + } + } + + return NGX_OK; +} + static ngx_int_t ngx_header_inspect_acceptcharset_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value) { ngx_int_t rc = NGX_AGAIN; ngx_uint_t i = 0; @@ -1148,6 +1167,11 @@ if ((rc != NGX_OK) && conf->block) { return NGX_HTTP_BAD_REQUEST; } + } else if ((h[i].key.len == 12) && (ngx_strcmp("Max-Forwards", h[i].key.data) == 0) ) { + rc = ngx_header_inspect_maxforwards_header(conf, r->connection->log, h[i].value); + if ((rc != NGX_OK) && conf->block) { + return NGX_HTTP_BAD_REQUEST; + } } else { /* TODO: support for other headers */ if (conf->log_uninspected) {