char *tmp_field;
core_server_config *conf = ap_get_core_module_config(r->server->module_config);
int strict = (conf->http_conformance != AP_HTTP_CONFORMANCE_UNSAFE);
+ int strictspaces = (conf->http_whitespace == AP_HTTP_WHITESPACE_STRICT);
/*
* Read header lines until we get the empty separator line, a read error,
}
memcpy(last_field + last_len, field, len +1); /* +1 for nul */
/* Replace obs-fold w/ SP per RFC 7230 3.2.4 */
- if (strict) {
+ if (strict || strictspaces) {
last_field[last_len] = ' ';
}
last_len += len;
return;
}
- if (!strict) {
+ if (!strict)
+ {
/* Not Strict ('Unsafe' mode), using the legacy parser */
+ if (strictspaces && strpbrk(last_field, "\n\v\f\r")) {
+ r->status = HTTP_BAD_REQUEST;
+ ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(03451)
+ "Request header presented bad whitespace "
+ "(disallowed by StrictWhitespace)");
+ return;
+ }
+ else {
+ char *ll = last_field;
+ while ((ll = strpbrk(ll, "\n\v\f\r")))
+ *(ll++) = ' ';
+ }
+
if (!(value = strchr(last_field, ':'))) { /* Find ':' or */
r->status = HTTP_BAD_REQUEST; /* abort bad request */
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00564)
return;
}
- tmp_field = value - 1; /* last character of field-name */
+ /* last character of field-name */
+ tmp_field = value - (value > last_field ? 1 : 0);
*value++ = '\0'; /* NUL-terminate at colon */
+ if (strictspaces && strpbrk(last_field, " \t")) {
+ r->status = HTTP_BAD_REQUEST;
+ ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(03452)
+ "Request header field name with whitespace "
+ "(disallowed by StrictWhitespace)");
+ return;
+ }
+
while (*value == ' ' || *value == '\t') {
++value; /* Skip to start of value */
}
/* Strip LWS after field-name: */
while (tmp_field > last_field
&& (*tmp_field == ' ' || *tmp_field == '\t')) {
- *tmp_field-- = '\0';
+ *(tmp_field--) = '\0';
+ }
+
+ if (tmp_field == last_field) {
+ r->status = HTTP_BAD_REQUEST;
+ ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(03453)
+ "Request header field name was empty");
+ return;
}
}
else /* Using strict RFC7230 parsing */