Skip to content

Commit

Permalink
feat(patches) remove nginx/openresty server header (#401)
Browse files Browse the repository at this point in the history
### Summary

Fix Kong/kong#7183

Co-authored-by: Aapo Talvensaari <[email protected]>
  • Loading branch information
dndx and bungle authored Jun 22, 2021
1 parent 9edd8f9 commit 1d05e41
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
3 changes: 3 additions & 0 deletions openresty-patches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ patching file lua-resty-core-0.1.21/lib/resty/core/socket_tcp.lua
patching file lua-resty-core-0.1.21/lib/resty/core/socket_tcp.lua
patching file lua-resty-core-0.1.21/lib/resty/core/socket_tcp.lua
patching file lua-resty-core-0.1.21/lib/resty/core/socket_tcp.lua
patching file lua-resty-core-0.1.21/lib/resty/core.lua
patching file lua-resty-core-0.1.21/lib/resty/core/socket_tcp.lua
patching file lua-resty-core-0.1.21/lib/ngx/balancer.lua
patching file lua-resty-websocket-0.08/lib/resty/websocket/client.lua
patching file nginx-1.19.3/src/http/ngx_http_upstream.c
patching file nginx-1.19.3/src/http/ngx_http_special_response.c
patching file nginx-1.19.3/src/stream/ngx_stream_proxy_module.c
patching file nginx-1.19.3/src/http/modules/ngx_http_grpc_module.c
patching file nginx-1.19.3/src/http/ngx_http_header_filter_module.c
patching file ngx_lua-0.10.19/src/ngx_http_lua_socket_tcp.c
patching file ngx_lua-0.10.19/src/ngx_http_lua_socket_tcp.h
patching file ngx_lua-0.10.19/src/ngx_http_lua_socket_tcp.c
Expand All @@ -63,6 +65,7 @@ patching file ngx_lua-0.10.19/src/ngx_http_lua_module.c
patching file ngx_lua-0.10.19/src/ngx_http_lua_balancer.c
patching file ngx_lua-0.10.19/src/ngx_http_lua_balancer.c
patching file ngx_lua-0.10.19/src/ngx_http_lua_common.h
patching file ngx_lua-0.10.19/src/ngx_http_lua_pipe.c
patching file ngx_stream_lua-0.0.9/src/api/ngx_stream_lua_api.h
```

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
From 42a44843445e9db12a8fc5eaf1f3e10b22a0065b Mon Sep 17 00:00:00 2001
From: Aapo Talvensaari <[email protected]>
Date: Tue, 15 Jun 2021 16:04:06 +0300
Subject: [PATCH] remove server headers from nginx header filter module

---
nginx-1.19.3/src/http/ngx_http_header_filter_module.c | 34 -------------------
1 file changed, 34 deletions(-)

diff --git a/nginx-1.19.3/src/http/ngx_http_header_filter_module.c b/nginx-1.19.3/src/http/ngx_http_header_filter_module.c
index ca13f2a..1a07dac 100644
--- a/nginx-1.19.3/src/http/ngx_http_header_filter_module.c
+++ b/nginx-1.19.3/src/http/ngx_http_header_filter_module.c
@@ -46,11 +46,6 @@ ngx_module_t ngx_http_header_filter_module = {
};


-static u_char ngx_http_server_string[] = "Server: openresty" CRLF;
-static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;
-static u_char ngx_http_server_build_string[] = "Server: " NGINX_VER_BUILD CRLF;
-
-
static ngx_str_t ngx_http_status_lines[] = {

ngx_string("200 OK"),
@@ -279,18 +274,6 @@ ngx_http_header_filter(ngx_http_request_t *r)

clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);

- if (r->headers_out.server == NULL) {
- if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_ON) {
- len += sizeof(ngx_http_server_full_string) - 1;
-
- } else if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_BUILD) {
- len += sizeof(ngx_http_server_build_string) - 1;
-
- } else {
- len += sizeof(ngx_http_server_string) - 1;
- }
- }
-
if (r->headers_out.date == NULL) {
len += sizeof("Date: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;
}
@@ -448,23 +431,6 @@ ngx_http_header_filter(ngx_http_request_t *r)
}
*b->last++ = CR; *b->last++ = LF;

- if (r->headers_out.server == NULL) {
- if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_ON) {
- p = ngx_http_server_full_string;
- len = sizeof(ngx_http_server_full_string) - 1;
-
- } else if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_BUILD) {
- p = ngx_http_server_build_string;
- len = sizeof(ngx_http_server_build_string) - 1;
-
- } else {
- p = ngx_http_server_string;
- len = sizeof(ngx_http_server_string) - 1;
- }
-
- b->last = ngx_cpymem(b->last, p, len);
- }
-
if (r->headers_out.date == NULL) {
b->last = ngx_cpymem(b->last, "Date: ", sizeof("Date: ") - 1);
b->last = ngx_cpymem(b->last, ngx_cached_http_time.data,
--
2.31.1

0 comments on commit 1d05e41

Please sign in to comment.