Re: [OT] HttpServletRequest.getRemoteAddr() sometimes returns NULL on Tomcat 9.0.30 and HTTP/2 secure requests

2020-02-05 Thread Manuel Dominguez Sarmiento

Yes, there are two reasons:

1) The Tomcat valves operate on all webapps. We only need/require this 
for one particular webapp without affecting the others.
2) The code has been simplified for illustration purposes. Besides 
X-Forwarded-For, we detect and work around many other custom external 
mobile proxies which do not use X-Forwarded-For and require custom 
Geolocation code to detect the ISP and connection type (Google 
Compression Proxy, Nokia OVI, Novarra, Lotus Flare, Opera Mini, Opera 
Max, Samsung Max, etc.) - this kind of customization is not possible 
without custom code. This filter is not meant for detecting internal 
proxies within our control (such as Apache front ends or load 
balancers), but rather public proxies which are "transparently" (not 
really) used via some mobile devices and services.

*
Manuel Dominguez Sarmiento*


-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Manuel,

On 2/5/20 12:12 PM, Manuel Dominguez Sarmiento wrote:

Our filter is not doing anything fancy (and it has always worked
correctly before we ran into this bug). In pseudo-code:

public doFilter(request, response) {

String ip = request.getRemoteAddr(); boolean isProxy =
isProxy(ip); if (isProxy) { String unwrappedIP =
unwrapXForwardedFor(request); chain.doFilter(new
MobileProxyHidingServletRequestWrapper(request, unwrappedIP),
response); } else { chain.doFilter(request, response); } }

All that MobileProxyHidingServletRequestWrapper is override
getRemoteAddr() returning unwrappedIP instead of delegating to the
actual request, while unwrapXForwardedFor() does what the name
suggests, which is processing X-Forwarded-For to obtain the
originating IP before it hit the detected proxy.

Any reason not to use the valves Tomcat provides to do pretty much
this exact thing?

https://tomcat.apache.org/tomcat-9.0-doc/config/valve.html#Remote_IP_Val
ve

- -chris
-BEGIN PGP SIGNATURE-
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl47AfoACgkQHPApP6U8
pFgywBAAxq4KZaxhO/X0EaoA3G3TDKURbDSrA2Hbke0QVgP3tX6QX6MDMEkbqTuv
x4S1xgXeNgWNIE9Dy62t4ciC6VZ21v6Rl4JMTOmtUO0ES+OBNTSYXstA1ZywBoMD
bRXHNjjdPtxAhhqQblfpKter+vn/k/PZ+45GgZSLNMrrJR+1idAafWs7YwpCHxfL
zh+C5C3uHu+bznCiOF/NQQ5d3/0mHyOj5nSpYx2ImSH+rgj0/Ch5w43L4chD1Lqj
aw2sqqC2z4Fzp3R8uNX/uMRV4flck9KILrfOe00BrMGVfPVuDDGa2J4NhSTs0oNx
Pda5j19QAP6wh6vIKH5KVM8fUWcb5KthcT34cxKttFl3gL0EedE40y97PHKxihJ5
BaT9M3MD0Lsh/mtgrSGcxHU1G0Vs5hHw9e9Zm0XqgQeLsuIALnSHcFyQcGBY05sH
9jljk/l+iMIp9xi3fXyCgYHRpCvbwOuT92V4pMYmwLCzvpfIrVspTi+7AxzbipBV
7tTvH4om0PSchj+Gj3ayOkQZsAyDZbJXbV4izxN3p1c8AJT5ZUmJnYqpKNtfAJpW
w/3OxIXoTUq3bbpb6AHrJe36+QU6+/C2WNqLBcevElr6T1oObKfzy1CjoUHxUQCm
wWxrSFac6atc56mVuPYAjs1DZ0sKpvts/ih6AwDF8+0jBzeJX+g=
=5GpE
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org





Re: [OT] HttpServletRequest.getRemoteAddr() sometimes returns NULL on Tomcat 9.0.30 and HTTP/2 secure requests

2020-02-05 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Manuel,

On 2/5/20 12:12 PM, Manuel Dominguez Sarmiento wrote:
> Our filter is not doing anything fancy (and it has always worked 
> correctly before we ran into this bug). In pseudo-code:
> 
> public doFilter(request, response) {
> 
> String ip = request.getRemoteAddr(); boolean isProxy =
> isProxy(ip); if (isProxy) { String unwrappedIP =
> unwrapXForwardedFor(request); chain.doFilter(new 
> MobileProxyHidingServletRequestWrapper(request, unwrappedIP),
> response); } else { chain.doFilter(request, response); } }
> 
> All that MobileProxyHidingServletRequestWrapper is override 
> getRemoteAddr() returning unwrappedIP instead of delegating to the 
> actual request, while unwrapXForwardedFor() does what the name
> suggests, which is processing X-Forwarded-For to obtain the
> originating IP before it hit the detected proxy.

Any reason not to use the valves Tomcat provides to do pretty much
this exact thing?

https://tomcat.apache.org/tomcat-9.0-doc/config/valve.html#Remote_IP_Val
ve

- -chris
-BEGIN PGP SIGNATURE-
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl47AfoACgkQHPApP6U8
pFgywBAAxq4KZaxhO/X0EaoA3G3TDKURbDSrA2Hbke0QVgP3tX6QX6MDMEkbqTuv
x4S1xgXeNgWNIE9Dy62t4ciC6VZ21v6Rl4JMTOmtUO0ES+OBNTSYXstA1ZywBoMD
bRXHNjjdPtxAhhqQblfpKter+vn/k/PZ+45GgZSLNMrrJR+1idAafWs7YwpCHxfL
zh+C5C3uHu+bznCiOF/NQQ5d3/0mHyOj5nSpYx2ImSH+rgj0/Ch5w43L4chD1Lqj
aw2sqqC2z4Fzp3R8uNX/uMRV4flck9KILrfOe00BrMGVfPVuDDGa2J4NhSTs0oNx
Pda5j19QAP6wh6vIKH5KVM8fUWcb5KthcT34cxKttFl3gL0EedE40y97PHKxihJ5
BaT9M3MD0Lsh/mtgrSGcxHU1G0Vs5hHw9e9Zm0XqgQeLsuIALnSHcFyQcGBY05sH
9jljk/l+iMIp9xi3fXyCgYHRpCvbwOuT92V4pMYmwLCzvpfIrVspTi+7AxzbipBV
7tTvH4om0PSchj+Gj3ayOkQZsAyDZbJXbV4izxN3p1c8AJT5ZUmJnYqpKNtfAJpW
w/3OxIXoTUq3bbpb6AHrJe36+QU6+/C2WNqLBcevElr6T1oObKfzy1CjoUHxUQCm
wWxrSFac6atc56mVuPYAjs1DZ0sKpvts/ih6AwDF8+0jBzeJX+g=
=5GpE
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: HttpServletRequest.getRemoteAddr() sometimes returns NULL on Tomcat 9.0.30 and HTTP/2 secure requests

2020-02-05 Thread Manuel Dominguez Sarmiento
Our filter is not doing anything fancy (and it has always worked 
correctly before we ran into this bug). In pseudo-code:


public doFilter(request, response) {

    String ip = request.getRemoteAddr();
    boolean isProxy = isProxy(ip);
    if (isProxy) {
        String unwrappedIP = unwrapXForwardedFor(request);
        chain.doFilter(new 
MobileProxyHidingServletRequestWrapper(request, unwrappedIP), response);

    } else {
        chain.doFilter(request, response);
    }
}

All that MobileProxyHidingServletRequestWrapper is override 
getRemoteAddr() returning unwrappedIP instead of delegating to the 
actual request, while unwrapXForwardedFor() does what the name suggests, 
which is processing X-Forwarded-For to obtain the originating IP before 
it hit the detected proxy.


*Manuel Dominguez Sarmiento*

On 05/02/2020 10:28, Mark Thomas wrote:

On 04/02/2020 22:27, Manuel Dominguez Sarmiento wrote:

We are getting the NPEs in a top-of-the-chain servlet filter which
decorates HttpServletRequest.getRemoteAddr() before actual servlet
processing. Only on HTTP/2 and in a very small number of cases. Perhaps
we should test 9.0.31 and see what happens. When is this new version due
for release?

I'm just working through back-porting some changes and then I'll be
starting the release process. It 9.0.31 should be available towards the
beginning of next week.

Can you expand on what your filter is doing? When is the call made to
HttpServletRequest.getRemoteAddr() on the original request?

Mark



Re: HttpServletRequest.getRemoteAddr() sometimes returns NULL on Tomcat 9.0.30 and HTTP/2 secure requests

2020-02-05 Thread Mark Thomas
On 04/02/2020 22:27, Manuel Dominguez Sarmiento wrote:
> We are getting the NPEs in a top-of-the-chain servlet filter which
> decorates HttpServletRequest.getRemoteAddr() before actual servlet
> processing. Only on HTTP/2 and in a very small number of cases. Perhaps
> we should test 9.0.31 and see what happens. When is this new version due
> for release?

I'm just working through back-porting some changes and then I'll be
starting the release process. It 9.0.31 should be available towards the
beginning of next week.

Can you expand on what your filter is doing? When is the call made to
HttpServletRequest.getRemoteAddr() on the original request?

Mark

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: RewriteValve does not work on HTTPS

2020-02-05 Thread Felix Schumacher

Am 04.02.2020 22:16, schrieb Hua Zhang:

What I mean with word 'works' is: the RewriteRule has been executed.

That is not the case by HTTPS. The rule has not been executed while the
RewriteCond is fulfilled.


Can you give us more information on your setup? Is there any 
Proxy/Loadbalancer in front of your tomcat? If so, can you show us 
details on that setup?

What is the value of the host request header in both cases?

Felix


Olaf Kock  于 2020年2月4日周二 下午9:06写道:



On 04.02.20 20:31, Hua Zhang wrote:
> Best tomcat team,
>
> Hereby I have a question about an issue I found by using RewriteValve
> on tomcat 9.30
>
> The rewrite.config is very simple:
>
> /RewriteCond %{HTTP_HOST} =youkoop.com 
> RewriteRule ^.*$ https://www.youkoop.com [R=301,L]
> /
>
> All I want is just redirect a naked root domain to a www domain with
> HTTPS.
>
> The redirection works on HTTP but not HTTPS.
>
> http://youkoop.com => https://www.youkoop.com *works*
>
Note: Images don't get through in this mailing list. I can imagine 
what

"works" means, but for your next example: Please elaborate what "does
not work" means.
>
> *https*://youkoop.com  =>
> https://www.youkoop.com *does not work*

First thing to test: Does https://youkoop.com work without the 
redirect,

then with the "wrong" host name? Otherwise it might be as simple as a
misconfigured TLS host that's never invoked because of a certificate
mismatch.

Olaf




-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org