Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration flag to hide kong headers #1009

Closed
elruwen opened this issue Feb 23, 2016 · 14 comments
Closed

Add configuration flag to hide kong headers #1009

elruwen opened this issue Feb 23, 2016 · 14 comments
Assignees
Labels
task/feature Requests for new features in Kong

Comments

@elruwen
Copy link

elruwen commented Feb 23, 2016

Hi!

If I currently do a kong request, the response contains the following headers:
'server': 'Apache-Coyote/1.1',
'via': 'kong/0.6.1',
'x-kong-proxy-latency': '0',
'x-kong-upstream-latency': '79'}

Server is the value from the upstream server, the rest is set by kong. While this is nice for debugging, I would prefer to hide those values from the public.

I would be nice to have a configuration flag to turn the exposure off.

Cheers
Ruwen

@subnetmarco subnetmarco self-assigned this Feb 26, 2016
@BrianHutchison
Copy link

+1

@thibaultcha
Copy link
Member

This also overlaps with #324, just in case someone is looking into it.

@markyjones
Copy link

I suspect others have already found work arounds for this but the simplest I have found is to add the following statements to the /etc/kong/kong.yml file to modify the nginx configuration.

        # Add additional response headers
        header_filter_by_lua_block {
           kong.header_filter()
           ngx.header["Server"] = nil
           ngx.header["Via"] = nil
           ngx.header["X-Kong-Proxy-Latency"] = nil
           ngx.header["X-Kong-Upstream-Latency"] = nil
        }

@manchuck
Copy link

manchuck commented Oct 6, 2016

Where would this go in the kong.conf for 0.9.1?

@mleace
Copy link

mleace commented Oct 24, 2016

Try modifying /usr/local/share/lua/5.1/kong/templates/kong/templates/nginx_kong.lua and restart Kong.

@elruwen
Copy link
Author

elruwen commented Nov 7, 2016

Hmm we run Kong on EC2 instances and simply install the kong rpm. Of course we can write some script, package it and let it do this modification. But it would be nice if there is a cleaner way.

@gabel
Copy link

gabel commented Jan 4, 2017

The response transfer plugin can only remove the X-Powered-By header but all others seem to be added later.

@elruwen You can have a look at #1842 (comment) perhaps this is a better way to solve it.

@bungle bungle assigned bungle and unassigned subnetmarco Mar 24, 2017
bungle added a commit that referenced this issue Mar 25, 2017
…cy tokens

* Add server_tokens and latency_tokens Kong configuration properties.

Fix #1009
thibaultcha pushed a commit that referenced this issue Mar 31, 2017
Add two new configuration properties `server_tokens` and
`latency_tokens` to toggle `Server` and `X-Kong-*-Latency` response
headers.

From #2259
Fix #1009
@thibaultcha
Copy link
Member

#2259 was just merged and allows to do this thanks to @bungle. Expect this to be released in the coming weeks. Thanks!

thibaultcha pushed a commit that referenced this issue Apr 28, 2017
Add two new configuration properties `server_tokens` and
`latency_tokens` to toggle `Server` and `X-Kong-*-Latency` response
headers.

From #2259
Fix #1009
thibaultcha pushed a commit that referenced this issue Apr 29, 2017
Add two new configuration properties `server_tokens` and
`latency_tokens` to toggle `Server` and `X-Kong-*-Latency` response
headers.

From #2259
Fix #1009
@ankit2894
Copy link

I tried adding above mentioned configuration nginx_kong.conf file and restarted the kong server in the meanwhile the file got overwritten with the default configuration and my changes disappeared.
Please help me starting kong server with custom nginx_kong.conf.

@elruwen
Copy link
Author

elruwen commented Sep 8, 2019

We are doing currently the following:

There is the file /usr/local/share/lua/5.1/kong/templates/nginx.lua (the exact path might be different on your system).

We added to the http section the following lines:

    more_clear_headers 'Server';
    server_tokens off;

@Edenshaw
Copy link

Edenshaw commented Dec 10, 2019

I found a solution for Kong 1.4.X (using database deployment, meaning there's no kong.yaml)

Execute elruwen's solution by editing the following file:

sudo vim /usr/local/share/lua/5.1/kong/templates/nginx.lua

You will find something like this:

http {
>  if #proxy_listeners > 0 or #admin_listeners > 0 then
    include 'nginx-kong.conf';
> end
}

Modify it by adding elruwnen's line, like this (if you add the line server_tokens off; kong won't start):

http {
>  if #proxy_listeners > 0 or #admin_listeners > 0 then
    include 'nginx-kong.conf';
> end
more_clear_headers 'Server';
}

Go and edit your kong.conf file:

sudo vim /etc/kong/kong.conf

Search for the headers section and edit it:

From this:

headers = server_tokens, latency_tokens

to this:

headers = off

restart kong

@Kishorelk
Copy link

How to remove the headers server:0.13.1 version

@SteveRuben
Copy link

How to remove the headers Server: kong/2.0.0 and use our own certificat in nginx

@hishamhm
Copy link
Contributor

hishamhm commented Sep 9, 2020

@Tryptich @Kishorelk See the documentation for the headers entry at: https://docs.konghq.com/2.1.x/configuration/#headers

It shouldn't be necessary to edit the nginx template, editing kong.conf should be sufficient. Note that in that case, by disabling Kong's Server header, it will still proxy the Server value provided by the upstream service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task/feature Requests for new features in Kong
Projects
None yet
Development

No branches or pull requests