Add secure flag to JSESSIONID cookie in spring automatically

后端 未结 5 813
广开言路
广开言路 2020-12-11 02:08

I have a tomcat application server that is behind a nginx. SSL terminates on the nginx. The Spring web-mvc application that is deployed on the tomcat should set the secure f

5条回答
  •  一向
    一向 (楼主)
    2020-12-11 02:32

    If you are using Spring Boot, there is a simple solution for it. Just set the following property in your application.properties:

    server.servlet.session.cookie.secure=true
    

    Source: Spring docs - Appendix A. Common application properties

    If you have some environment with HTTPS and some without it, you will need to set it to false in profiles without HTTPS. Otherwise the Secure cookie is ignored.

提交回复
热议问题