question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

grpc-dotnet + Blazor sets Safari and Firefox User-Agent to "grpc-dotnet/$assemblyVersion"

See original GitHub issue

Describe the bug

When using grpc-dotnet and Blazor together to call a GRPC API, the User-Agent is set to “grpc-dotnet/$assemblyVersion” in Safari and Firefox. In Chrome and Edge it is the actual browser User-Agent.

https://docs.microsoft.com/en-us/aspnet/core/grpc/services?view=aspnetcore-5.0 for example describes how to read the User-Agent:

public override Task<ExampleResponse> UnaryCall(ExampleRequest request, ServerCallContext context)
{
    var userAgent = context.RequestHeaders.GetValue("user-agent");
    // ...

    return Task.FromResult(new ExampleResponse());
}

(Migrated from https://github.com/dotnet/AspNetCore.Docs/issues/21178)

To Reproduce

Use GRPC with Blazor as described at https://docs.microsoft.com/en-us/aspnet/core/grpc/browser?view=aspnetcore-5.0 and look at the traffic in Safari. The User-Agent will be for example “grpc-dotnet/2.34.0.0”.

You can also check out https://our.gatekeeper.page in Safari or Firefox and look at the request to the “WhoAmI” endpoint to see the header being wrong. The code for this can be found at https://github.com/getgatekeeper/server.

The Blazor example from https://github.com/grpc/grpc-dotnet/tree/master/examples/Blazor should also have the same issue.

The issue seems potentially related to the following piece of code in Grpc.Net.Client/Internal/GrpcCall.cs. I wonder if Chrome/Edge just ignore the header being overwritten whilst Safari and Firefox obeys it:

// User agent is optional but recommended.
headers.TryAddWithoutValidation(GrpcProtocolConstants.UserAgentHeader, GrpcProtocolConstants.UserAgentHeaderValue);

Test plan

Browser Sends correct User-Agent Screenshot
Safari image
Firefox image
Chrome image
Edge image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
BrennanConroycommented, Jan 10, 2021

SignalR sets the “X-SignalR-User-Agent” header.

https://github.com/dotnet/aspnetcore/blob/020145ded2fd7ea4657f220e000d64d41232bec3/src/SignalR/clients/ts/signalr/src/Utils.ts#L201

I believe the reason we don’t set “User-Agent” is because it used to be a forbidden header but no longer is. Also, Chrome just drops the header? https://bugs.chromium.org/p/chromium/issues/detail?id=571722

0reactions
JamesNKcommented, Jan 12, 2021

gRPC fixed. Re-opening for SignalR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A new experiment: Call .NET gRPC services from the ...
NET Core gRPC client to call gRPC-Web services. (great for Blazor WebAssembly apps!) New opportunites with gRPC-Web. Call ASP.NET Core gRPC apps ...
Read more >
How to replace default user-agent sent with gRPC request ...
If I tried to set the user-agent header value manually using the following code: public class Dummy { private readonly OrderingService.
Read more >
How to use gRPC-Web with Blazor WebAssembly on App ...
NET 5.0 in the drop-down, highlight the Blazor WebAssembly App option and check the ASP.NET Core hosted option under the Advanced column before ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found