#1 2020-05-22 09:28:52

jaclas
Member
Registered: 2014-09-12
Posts: 215

RemoteIP in request context - dissapear?

A few days ago I updated mORMot to the latest version and it turned out that the read client's IP  stopped working. I'm using interface-based services.

The code I was using to read the client's IP:

  sIP := FindIniNameValue(Pointer(ServiceContext.Request.Call.InHead), 'REMOTEIP: ');

or

  sIP := FindNameValue(Pointer(ServiceContext.Request.Call.InHead), HEADER_REMOTEIP_UPPER);

Now sIP is empty. How repair this behaviour?

Offline

#2 2020-05-22 10:43:20

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: RemoteIP in request context - dissapear?

I debug source, in SynCRTSock.pas method RetrieveHeaders() fill RemoteIP param as ermpty string when IP = localhost:

K5EXcHgAj49JVVv2HcKxXy8cI7AWTZ90WexYm7Zv1Y0rPvMXXxPqQoSZMtrbNQAF.png


Is this the intended change or should it return '127.0.0.1' or '::1'?

Last edited by jaclas (2020-05-22 11:01:12)

Offline

#3 2020-05-22 11:27:58

Junior/RO
Member
Registered: 2011-05-13
Posts: 207

Re: RemoteIP in request context - dissapear?

Try using git bisect to find which was the commit where the bug happens.

Offline

#4 2020-05-22 14:12:31

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: RemoteIP in request context - dissapear?

I try, but without sucess... too many commits :-)

Offline

#5 2020-05-22 14:55:39

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,534
Website

Re: RemoteIP in request context - dissapear?

most likely this commit
For complex git operations like resolve huge merge conflicts, find changes inside some block of code etc. I use WebStorm (intellij idea) - the best IDE for sure, perfect Git integration. Understand all popular programing languages

Offline

#6 2020-05-22 17:12:07

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,183
Website

Re: RemoteIP in request context - dissapear?

This was a feature.

No IP means localhost.

Offline

#7 2020-05-30 16:16:04

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,534
Website

Re: RemoteIP in request context - dissapear?

@ab - can I ask you to revert back feature with empty RemoteIP for local address for both plain socket and HTTP API servers ( by remove  {localasvoid=}true here  and here in SynCrtSock.pas)

This changes broke my code in very chimeric way:
I have some secured endpoints what allowed to be executed only from certain IPs (IP masks). The caller IP can come either from socket or from HTTP header (in case we are behind reverse proxy).
After changes {localasvoid=}true  I can't decide is caller IP is a local address what comes from socket or this is empty X-Real-IP header.

Last edited by mpv (2020-05-30 16:17:04)

Offline

#8 2020-06-01 19:11:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,183
Website

Re: RemoteIP in request context - dissapear?

Please check https://synopse.info/fossil/info/3304d25391

Thanks for the feedback.

Offline

#9 2020-06-10 12:55:29

HgAlexx
Member
Registered: 2020-06-10
Posts: 6

Re: RemoteIP in request context - dissapear?

Hi,


A related issue I've just found, in procedure "THttpApiServer.Execute" (SynCrtSock.pas):

The "RemoteIP" header is properly set, however "Context.fRemoteIP" is never set.


Regards,

Offline

#10 2021-01-14 16:43:18

George
Member
Registered: 2016-04-05
Posts: 140

Re: RemoteIP in request context - dissapear?

Hi!

SynCrtSock.pas

6608 ctxt.Prepare(URL,Method,HeaderGetText(fRemoteIP),Content,ContentType,'',ClientSock.fTLS);

Why aRemoteIP is empty string here?

6608 ctxt.Prepare(URL,Method,HeaderGetText(fRemoteIP),Content,ContentType,fRemoteIP,ClientSock.fTLS);

With that change, Ctxt.RemoteIP from THttpServer.OnRequest handler will be filled.

Last edited by George (2021-01-14 16:46:06)

Offline

Board footer

Powered by FluxBB