You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Hendy Irawan <he...@soluvas.com> on 2017/08/08 00:39:51 UTC

How to "force" page redirects to HTTPS?

Hi,

My setup is:

Wicket 7.8 running in Spring Boot (HTTP:8080) <--served by-- nginx (HTTP:80)
<--CDNed by-- CloudFlare (HTTPS:443)

This works almost well, however everytime Wicket issues a redirect it always
goes to http://version first, which is intercepted by CloudFlare then
immediately redirected back again to the HTTPS version. This is inefficient
(and may be why sometimes I experience certain issues with sessions, etc.)

What I'd like to do is so that Wicket always redirects *to* HTTPS (only for
Wicket pages, not manual URLs), or using predefined base URI that I set. I
set a base URI manually because e.g. I want to send email outside of Wicket,
the email needs to contain a link to the website, so the base URI needs to
be known. I'd like to use this base URI configuration with Wicket too.

However I don't want to use @RequireHttps because to the app server/Tomcat,
it always comes as a plain HTTP request.

Please help, thank you.

Hendy

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-force-page-redirects-to-HTTPS-tp4678479.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to "force" page redirects to HTTPS?

Posted by Bas Gooren <ba...@iswd.nl>.
Well, all redirects are mapped by the SystemMapper (and its child mappers);
So if you are certain that it’s mapped inside your HttpsMapper, that should
not be the problem.

Have you set a breakpoint inside BufferedWebResponse#sendRedirect? You
should check what url it receives and if it is a http url, whether the url
generation went through your HttpsMapper.
This also allows you to detect if the container is interfering (your app
server or reverse proxy).

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 8 augustus 2017 bij 12:50:47, Hendy Irawan (hendy@soluvas.com) schreef:

Thanks Sebastian for the hint.

But yes, I've mapped all pages before calling setRootRequestMapper.
I also put logs in my getDesiredSchemeFor and they're being called, and
returning HTTPS for all calls.

But is it possible there are some cases it's not being called (?) Or
perhaps
the ?1 stateful redirect is handled differently?

My current issue is only with the redirects. Everything else seems to be
fine...

Hendy

-- 
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/How-to-force-page-redirects-to-HTTPS-tp4678479p4678484.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org

Re: How to "force" page redirects to HTTPS?

Posted by Hendy Irawan <he...@soluvas.com>.
Thanks Sebastian for the hint.

But yes, I've mapped all pages before calling setRootRequestMapper.
I also put logs in my getDesiredSchemeFor and they're being called, and
returning HTTPS for all calls.

But is it possible there are some cases it's not being called (?) Or perhaps
the ?1 stateful redirect is handled differently?

My current issue is only with the redirects. Everything else seems to be
fine...

Hendy

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-force-page-redirects-to-HTTPS-tp4678479p4678484.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to "force" page redirects to HTTPS?

Posted by Bas Gooren <ba...@iswd.nl>.
Hi!

How and when are you mounting your pages?

If you are mounting them _after_ installing the HttpsMapper, then those
pages will not be mapped “under” https.
This is because a compound request mapper is created on demand when
mounting pages, in case the current root mapper is not already a compound
mapper.

Please confirm if you are, in fact, mounting pages after your call to
setRootRequestMapper.

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 8 augustus 2017 bij 12:39:12, Hendy Irawan (hendy@soluvas.com) schreef:

I have managed to use XForwardedRequestWrapperFactory by creating a Filter.
I also use HttpsMapper as follows :

setRootRequestMapper(new HttpsMapper(getRootRequestMapper(), new
HttpsConfig()) {
@Override
protected Scheme getDesiredSchemeFor(IRequestHandler handler) {
final HttpServletRequest request = (HttpServletRequest)
RequestCycle.get().getRequest().getContainerRequest();
// Assume runtime deployment is always reverse proxied and
SSL-terminated by load balancer
// WARNING: This requires proper
XForwardedRequestWrapperFactory configuration AND nginx configuration
final Scheme desiredScheme =
"https".equalsIgnoreCase(request.getScheme()) ? Scheme.HTTPS :
super.getDesiredSchemeFor(handler);
log.debug("Scheme: {} Secure: {} Remote Addr: {}
desiredScheme for {}: {}",
request.getScheme(), request.isSecure(),
request.getRemoteAddr(),
null != handler ? handler.getClass().getSimpleName()
: null, desiredScheme);
return desiredScheme;
}
});

However, even though I've confirmed that XForwardedRequestWrapperFactory
works as intended (settings scheme=https and isSecure=true),
getDesiredSchemeFor() always returns HTTPS in my case, initial redirect for
stateful pages are always done using HTTP. i.e. from https://.../match/edit
redirected to http://.../match/edit?1, while I would expect it to be
redirected to https://.../match/edit?1

Please help, thank you in advance.

-- 
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/How-to-force-page-redirects-to-HTTPS-tp4678479p4678482.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org

Re: How to "force" page redirects to HTTPS?

Posted by Hendy Irawan <he...@soluvas.com>.
I have managed to use XForwardedRequestWrapperFactory by creating a Filter.
I also use HttpsMapper as follows :

        setRootRequestMapper(new HttpsMapper(getRootRequestMapper(), new
HttpsConfig()) {
            @Override
            protected Scheme getDesiredSchemeFor(IRequestHandler handler) {
                final HttpServletRequest request = (HttpServletRequest)
RequestCycle.get().getRequest().getContainerRequest();
                // Assume runtime deployment is always reverse proxied and
SSL-terminated by load balancer
                // WARNING: This requires proper
XForwardedRequestWrapperFactory configuration AND nginx configuration
                final Scheme desiredScheme =
"https".equalsIgnoreCase(request.getScheme()) ? Scheme.HTTPS :
super.getDesiredSchemeFor(handler);
                log.debug("Scheme: {} Secure: {} Remote Addr: {}
desiredScheme for {}: {}",
                        request.getScheme(), request.isSecure(),
request.getRemoteAddr(),
                        null != handler ? handler.getClass().getSimpleName()
: null, desiredScheme);
                return desiredScheme;
            }
        });

However, even though I've confirmed that XForwardedRequestWrapperFactory
works as intended (settings scheme=https and isSecure=true),
getDesiredSchemeFor() always returns HTTPS in my case, initial redirect for
stateful pages are always done using HTTP. i.e. from https://.../match/edit
redirected to http://.../match/edit?1, while I would expect it to be
redirected to https://.../match/edit?1

Please help, thank you in advance.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-force-page-redirects-to-HTTPS-tp4678479p4678482.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to "force" page redirects to HTTPS?

Posted by Hendy Irawan <he...@soluvas.com>.
This seems to be interesting:

* https://issues.apache.org/jira/browse/WICKET-3015
* https://issues.apache.org/jira/browse/WICKET-3009

But how to use it?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-force-page-redirects-to-HTTPS-tp4678479p4678480.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org