How to avoid Wicket redirecting page from HTTPS to HTTP

Viewed 322

I use wicket 8.10, it is installed on tomcat and proxied by nginx. SSL certificates configured in nginx config. Also Nginx forwards all HTTP requests to HTTPS.

The problem is following:

When I submit any form wicket returns response headers where the Location tag contains url with HTTP protocol.

Why it is important:

The last chrome update makes browser show alert when Location contains HTTP protocol on page opened by HTTPS. Before that, nginx quietly redirected the request, but now user see alert page from browser (similar to when certificate is invalid or absence).

2 Answers

The problem here is that your Wicket application does not know that it is behind a proxy.

There are two solutions:

  1. use XForwardedRequestWrapperFactory

It will wrap the Tomcat's HttpServletRequest with one that reads X-Forwarded-*** request headers. Just make sure that Nginx exports X-Forwarded-Proto request header

  1. use HttpsMapper

Just overwrite protected Scheme getDesiredSchemeFor(Class<? extends IRequestablePage> pageClass) to return Scheme.HTTPS in PRODUCTION mode and Scheme.HTTP in DEVELOPMENT mode (I assume you don't use Nginx proxy while developing)

Related