Inspect Content-MD5 header, fixes #25
1 parent 491232d commit c8bf42f864e9dab35d5ce204b4ac3c1c83375733
@Andreas Jaggi Andreas Jaggi authored on 18 Sep 2011
x-way committed on 18 Sep 2011
Showing 2 changed files
View
2
■■■
README
Accept-Encoding, Accept-Language, Accept-Charset, Max-Forwards,
If-Match, If-None-Match, Last-Modified, Content-Length,
Expires, Content-Language, Content-Encoding, Allow, Host,
Accept, Connection, Content-Range, User-Agent, Upgrade, Via,
From, Pragma, Content-Type
From, Pragma, Content-Type, Content-MD5
 
Report Bugs
Create a ticket on the issue tracking interface of GitHub:
http://github.com/x-way/ngx_http_header_inspect/issues
View
54
ngx_http_header_inspect.c
static ngx_int_t ngx_header_inspect_from_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_pragma_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value);
static ngx_int_t ngx_header_inspect_contenttype_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value);
static ngx_int_t ngx_header_inspect_contentmd5_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);
 
static void *ngx_header_inspect_create_conf(ngx_conf_t *cf);
 
return rc;
}
 
static ngx_int_t ngx_header_inspect_contentmd5_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value) {
ngx_uint_t i;
u_char d;
 
if ( value.len == 0 ) {
if ( conf->log ) {
ngx_log_error(NGX_LOG_ALERT, log, 0, "header_inspect: empty Content-MD5 header");
}
return NGX_ERROR;
}
 
for ( i = 0; i < value.len; i++ ) {
d = value.data[i];
 
if ( (d >= '0') && (d <= '9') ) {
continue;
}
if ( (d >= 'a') && (d <= 'z') ) {
continue;
}
if ( (d >= 'A') && (d <= 'Z') ) {
continue;
}
if ( (d == '+') || (d == '/') ) {
continue;
}
if ( d == '=' ) {
i++;
while ( i < value.len ) {
if ( value.data[i] != '=' ) {
if ( conf->log ) {
ngx_log_error(NGX_LOG_ALERT, log, 0, "header_inspect: trailing characters at position %d in Content-MD5 header \"%s\"", i, value.data);
}
return NGX_ERROR;
}
i++;
}
break;
}
if ( conf->log ) {
ngx_log_error(NGX_LOG_ALERT, log, 0, "header_inspect: illegal character at position %d in Content-MD5 header \"%s\"", i, value.data);
}
return NGX_ERROR;
}
 
return NGX_OK;
}
 
static ngx_int_t ngx_header_inspect_contenttype_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value) {
ngx_uint_t v;
 
if ( value.len < 3 ) {
rc = ngx_header_inspect_contenttype_header(conf, r->connection->log, h[i].value);
if ((rc != NGX_OK) && conf->block) {
return NGX_HTTP_BAD_REQUEST;
}
} else if ((h[i].key.len == 11) && (ngx_strcmp("Content-MD5", h[i].key.data) == 0) ) {
rc = ngx_header_inspect_contentmd5_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) {
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, "header_inspect: uninspected header \"%s: %s\"", h[i].key.data, h[i].value.data);