Sergey Kandaurov
September 01, 2023 11:54AM
details: https://hg.nginx.org/nginx/rev/35bb47f65cab
branches:
changeset: 9155:35bb47f65cab
user: Maxim Dounin <mdounin@mdounin.ru>
date: Thu Aug 31 22:59:17 2023 +0300
description:
Upstream: fixed handling of Status headers without reason-phrase.

Status header with an empty reason-phrase, such as "Status: 404 ", is
valid per CGI specification, but looses the trailing space during parsing.
Currently, this results in "HTTP/1.1 404" HTTP status line in the response,
which violates HTTP specification due to missing trailing space.

With this change, only the status code is used from such short Status
header lines, so nginx will generate status line itself, with the space
and appropriate reason phrase if available.

Reported at:
https://mailman.nginx.org/pipermail/nginx/2023-August/EX7G4JUUHJWJE5UOAZMO5UD6OJILCYGX.html

diffstat:

src/http/modules/ngx_http_fastcgi_module.c | 5 ++++-
src/http/modules/ngx_http_scgi_module.c | 5 ++++-
src/http/modules/ngx_http_uwsgi_module.c | 5 ++++-
3 files changed, 12 insertions(+), 3 deletions(-)

diffs (45 lines):

diff -r f6b6f3dd7ca0 -r 35bb47f65cab src/http/modules/ngx_http_fastcgi_module.c
--- a/src/http/modules/ngx_http_fastcgi_module.c Thu Aug 31 10:54:07 2023 +0400
+++ b/src/http/modules/ngx_http_fastcgi_module.c Thu Aug 31 22:59:17 2023 +0300
@@ -2048,7 +2048,10 @@ ngx_http_fastcgi_process_header(ngx_http
}

u->headers_in.status_n = status;
- u->headers_in.status_line = *status_line;
+
+ if (status_line->len > 3) {
+ u->headers_in.status_line = *status_line;
+ }

} else if (u->headers_in.location) {
u->headers_in.status_n = 302;
diff -r f6b6f3dd7ca0 -r 35bb47f65cab src/http/modules/ngx_http_scgi_module.c
--- a/src/http/modules/ngx_http_scgi_module.c Thu Aug 31 10:54:07 2023 +0400
+++ b/src/http/modules/ngx_http_scgi_module.c Thu Aug 31 22:59:17 2023 +0300
@@ -1153,7 +1153,10 @@ ngx_http_scgi_process_header(ngx_http_re
}

u->headers_in.status_n = status;
- u->headers_in.status_line = *status_line;
+
+ if (status_line->len > 3) {
+ u->headers_in.status_line = *status_line;
+ }

} else if (u->headers_in.location) {
u->headers_in.status_n = 302;
diff -r f6b6f3dd7ca0 -r 35bb47f65cab src/http/modules/ngx_http_uwsgi_module.c
--- a/src/http/modules/ngx_http_uwsgi_module.c Thu Aug 31 10:54:07 2023 +0400
+++ b/src/http/modules/ngx_http_uwsgi_module.c Thu Aug 31 22:59:17 2023 +0300
@@ -1381,7 +1381,10 @@ ngx_http_uwsgi_process_header(ngx_http_r
}

u->headers_in.status_n = status;
- u->headers_in.status_line = *status_line;
+
+ if (status_line->len > 3) {
+ u->headers_in.status_line = *status_line;
+ }

} else if (u->headers_in.location) {
u->headers_in.status_n = 302;
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Upstream: fixed handling of Status headers without reason-phrase.

Sergey Kandaurov 401 September 01, 2023 11:54AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 128
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready