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

X-Application-Context HTTP response header exposes internal server port #1308

Closed
gmarziou opened this issue Jul 29, 2014 · 9 comments
Closed
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@gmarziou
Copy link

Using spring-boot 1.1.4.

Spring-boot-actuator's EndpointWebMvcAutoConfiguration.ApplicationContextFilterConfiguration registers a Filter that adds a response header X-Application-Context that contains the application id but it does not remove it and so the browser gets it.

By default, the application id is something like this "application:int:8080" which is a concatenation of the "application" (?), profile and server port.

In the scenario where the application is behind a reverse proxy, I find it a bit unsafe to expose the internal port number even though it should be not accessible from the external world.

Is there a way to disable this behavior without breaking actuator?

@philwebb
Copy link
Member

There isn't currently a simple way to disable that header, but we can certainly add an option. In the meantime it appears that the header is actually exposing the ApplicationContext ID (take a look at EndpointWebMvcAutoConfiguration). The ID is set by ContextIdApplicationContextInitializer so the easiest fix is to replace context ID before requests are served.

Something like:

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleTomcatApplication.class, args).setId("myapp");
    }

Should do the trick.

@philwebb philwebb added this to the 1.1.5 milestone Jul 30, 2014
@gmarziou
Copy link
Author

Thanks Phil for your answer, unfortunately the setId() comes too late because the init is done by the run().

@dsyer
Copy link
Member

dsyer commented Aug 4, 2014

Apps in cloudfoundry don't have the port in the application context id, so it must be possible to change this behaviour if you need to. That works by just registering a listener that sets the context id.

Just out of interest: what exactly is the security issue (i.e. what could a bad guy do with the port information that he couldn't do without it)?

@gmarziou
Copy link
Author

gmarziou commented Aug 5, 2014

Being a good guy, I don't know ;) but I think the less information leaks is the best anyway.
Maybe CloudFoundry could say why they did it.

@bep
Copy link
Contributor

bep commented Aug 5, 2014

I worked for customers being paranoid about leaking anything about the environment (that its running on Tomcat, internal ports etc.).

But this is a perfect task to let the reverse proxy handle - by having it removing those headers.

@dsyer
Copy link
Member

dsyer commented Aug 5, 2014

It isn't cloudfoundry that changes the header, it's the VcapApplicationListener in Spring Boot. I was just using that as an example to demonstrate that you can customize it in the app if you want to.

@dsyer
Copy link
Member

dsyer commented Aug 6, 2014

Looking at the source code for ContextIdApplicationContextInitializer I can see that you only need to set spring.application.index to non-null to change the port to an arbitrary opaque value of your choice.

@philwebb philwebb self-assigned this Aug 6, 2014
philwebb pushed a commit that referenced this issue Aug 6, 2014
Add `management.add-application-context-header` option to disable
the automatic adding of the `X-Application-Context` HTTP header.

Fixed gh-1308
@gmarziou
Copy link
Author

gmarziou commented Aug 7, 2014

Setting spring.application.name and spring.application.index in application.yml is a good solution.
Thanks

@pires
Copy link

pires commented Apr 6, 2016

Also, management.add-application-context-header: false disables this completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants