Situation A
NGINX 1.26.x or 1.25.x and NO OTEL cpp-contrib added.
Requests made with curl, python httpclient are accepted.
Requests made with dotnet 8.0 httpclient are acceepted.
Situation B
NGINX 1.26.x or 1.25.x and OTEL cpp-contrib added.
Requests made with curl, python httpclient are accepted.
Requests made with dotnet 8.0 httpclient are REJECTED.
The following log is produced by .net:
An error occurred while sending the request.
The response ended prematurely. (ResponseEnded)
at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnection.d57.MoveNext() in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs:line 862
at System.Net.Http.HttpConnectionPool.d_89.MoveNext() in //src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs:line 1116
at System.Threading.Tasks.ValueTask`1.getResult() in //src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs:line 812
at System.Net.Http.RedirectHandler.d4.MoveNext() in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/RedirectHandler.cs:line 30
at System.Net.Http.HttpClient.d_41.MoveNext() in //src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.cs:line 188
at CSOTel.Traffic.CLI.Program.d__1.MoveNext() in C:\Users\tomek\source\repos\CSOTel\CSOTel.Traffic.CLI\Program.cs:line 35
The following is produced by nginx with otel cpp contrib:
While curl works perfecly fine and nginx serves the request.
The problem is that curl automatically adds a user-agent header, but dotnet httpclient doesn't - and why should it?
old SSL session ID is stale, removing
< HTTP/1.1 200 OK
< Server: nginx/1.26.0
< Date: Mon, 26 Aug 2024 19:26:36 GMT
< Content-Type: text/html
< Content-Length: 2408
< Connection: keep-alive
< Last-Modified: Sun, 25 Aug 2024 15:13:43 GMT
< ETag: "66cb4a27-968"
< Accept-Ranges: bytes
<
<!DOCTYPE html>
FIX/SOLUTION/WORKAROUND
Workaround is to add User-Agent header to dotnet httpclient (any value works), but the key must be present. Otherwise the nignx will reject the request.
NOTE
This happens ONLY when nginx is instrumented with this cpp-contrib library! So it's clearly an issue with this solution - probably some kind of null exception is thrown underneath and even no TRACE is being sent to OTEL collector, because the worker thread is automatically killed.
We have experienced the same. Any request without the user-agent header set is rejected. Even worst, it kills the worker process.
It is easy enough to produce a DoS by miss configuring with this.
Situation A NGINX 1.26.x or 1.25.x and NO OTEL cpp-contrib added. Requests made with curl, python httpclient are accepted. Requests made with dotnet 8.0 httpclient are acceepted.
Situation B NGINX 1.26.x or 1.25.x and OTEL cpp-contrib added. Requests made with curl, python httpclient are accepted. Requests made with dotnet 8.0 httpclient are REJECTED.
The following log is produced by .net:
The following is produced by nginx with otel cpp contrib:
While curl works perfecly fine and nginx serves the request. The problem is that curl automatically adds a user-agent header, but dotnet httpclient doesn't - and why should it?
FIX/SOLUTION/WORKAROUND Workaround is to add User-Agent header to dotnet httpclient (any value works), but the key must be present. Otherwise the nignx will reject the request.
NOTE This happens ONLY when nginx is instrumented with this cpp-contrib library! So it's clearly an issue with this solution - probably some kind of null exception is thrown underneath and even no TRACE is being sent to OTEL collector, because the worker thread is automatically killed.