You are not logged in.
Hi @ab, I have an issue with TRestHttpClient.SetUser which is not working starting on this specific commit, and tested yet only on Delphi 12.3
65e4597 - rest: make server nonce unique per connection/client - our authentication scheme is now as secure as SCRAM could be, and even more since we feature strong "Modular Crypt" hashes like BCrypt or SCrypt
- still compatible with old mORMot 1 clients
What happen:
- It work using direct connection to server host (localhost, 192.168.*)
- it doesn't work behind NGINX on 80/http and 443/https
I havn't debugged yet as you might have an answer.
On the test program shown below, the client is a simple TRestHttpClient.SetUser and compiled on commit a919746 from july, 29. I get the same result compiling both server and client on commit 65e4597 or newer. I have saved logs just in case.
Client on left side get HTTP 200, on right side the client get a HTTP 403 return code.
Last edited by flydev (2025-09-26 19:50:15)
Offline
I don't understand why there should be any difference behind nginx/https.
Take a look at the logs to debug a little bit and find out what happens in the mormot server behind nginx.
Check your nginx configuration, and the fact that the /auth URI should be passed to mormot with its parameters.
Offline
I will look at it, the nginx config was kept minimal with a simple proxy_pass for testing. The demo program return both 200 OK (direct and nginx) if the server is compiled on last commit before 65e4597. Once I compile the server starting on commit 65e4597, then it fail on nginx only..
I will try again with a minimal server and report it here.
Last edited by flydev (2025-09-29 14:19:06)
Offline
Now I think I understand the issue.
This commit added an additional safety, by using a nonce per connection.
But behind nginx, Ctxt.Call^.LowLevelConnectionID may not be used.
You could either
1) set the rsoSharedNonce option to TRestServer,
or
2) properly configure the ConnectionID header for nginx:
a) set in your code: THttpServerGeneric.RemoteConnIDHeader='X-Conn-ID'
b) set in nginx config: proxy_set_header X-Conn-ID $connection
Proper nginx configuration is the following:
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Conn-ID $connection
Edit:
To avoid such issue, I may just invert the logic, and use a new explicit rsoPerConnectionNonce so disable this new feature by default.
https://github.com/synopse/mORMot2/commit/1fcc7f0e7
Now it should work with no problem and no needed more configuration.
Sorry for the confusion.
Offline
I have added https://github.com/synopse/mORMot2/commit/1fcc7f0e7
so maybe it would work out of the box directly without changing the option.
If you set the X-Conn-ID header, you could enable this new rsoPerConnectionNonce option, for safety.
But it is not mandatory.
Offline
Hi @ab, I did some testing - Delphi 12.3 and FPC - and then:
- without rsoPerConnectionNone, client auth is fine (this was failing).
- enabling rsoPerConnectionNone, client fail at CheckPassoword()
fServer.fOptions:
[rsoNoInternalState,rsoNoTableURI,rsoMethodUnderscoreAsSlashUri,rsoPerConnectionNonce]
srvr mormot.rest.server.TRestServerRoutingRest(0334c340) Method GET root/auth?username=Admin=200 out=77 B in 3.09s
ret ServerApiHost.TAppServer(033e9f40) Method len=77 {"result":"bd1a5ead8e255448fd09484e56e33a66ea8cefc3f6d3804735cb6cf7a46881c0"}
[debug] GET /root/auth?username=Admin&password=e23f6a5756da303c6b36de49077cb51d6828768a2763b0b82678122deba05ac8&clientnonce=58671B01_0fb7691644db0de2e1bd776ed8466eb2
[BeforeBody][aInHeaders]:
- X-Real-IP: 127.0.0.1
- X-Forwarded-For: 127.0.0.1
- X-Forwarded-Proto: https
- X-Conn-ID: 17
- Accept: */*
Offline
If you enable rsoPerConnectionNonce, you need to
1) set the header at nginx level - seems done
2) set THttpServerGeneric.RemoteConnIDHeader := 'X-Conn-ID' at mormot server side - is it done?
Offline
I tried to make it more explicit in the documentation:
https://github.com/synopse/mORMot2/commit/d8d29e033
Offline