TauriKit.Sidecar.Loopback
0.13.0
See the version list below for details.
dotnet add package TauriKit.Sidecar.Loopback --version 0.13.0
NuGet\Install-Package TauriKit.Sidecar.Loopback -Version 0.13.0
<PackageReference Include="TauriKit.Sidecar.Loopback" Version="0.13.0" />
<PackageVersion Include="TauriKit.Sidecar.Loopback" Version="0.13.0" />
<PackageReference Include="TauriKit.Sidecar.Loopback" />
paket add TauriKit.Sidecar.Loopback --version 0.13.0
#r "nuget: TauriKit.Sidecar.Loopback, 0.13.0"
#:package TauriKit.Sidecar.Loopback@0.13.0
#addin nuget:?package=TauriKit.Sidecar.Loopback&version=0.13.0
#tool nuget:?package=TauriKit.Sidecar.Loopback&version=0.13.0
TauriKit.Sidecar.Loopback
The .NET host side of a desktop app's loopback backend — the counterpart of the
tauri-kit-sidecar crate's
loopback feature, released under the same version.
The backend listens on 127.0.0.1 only, on a port the system picks, and its callers learn where it is in one of two ways:
- Started by the app as its child. The app passes a fresh random token in an environment
variable (
LoopbackHost.ReadToken), and the backend announces its port as a line on standard output (RunAnnouncingAsync), which the app waits for. - Living on its own, outliving the app's windows. The backend issues its credential itself and
publishes it with its port in a discovery file (
RunPublishingAsync). Only the person running the backend can read that file: on Windows its access list grants that user and the system and nothing else, and elsewhere its mode is 0600. The file is written beside its place and moved in, so a reader never sees half of one. It carries the process id and start time, soDiscoveryFile.TryReadtells a file left by a backend that died (Stale) from a missing or damaged one. A new credential is issued on every start, so a caller re-reads the file once when it gets a 401.
Either way, requests are checked the same way:
- Every route needs a registered caller unless it is named open.
AddLoopbackAuthenticationmakes bearer authentication againstLoopbackCredentialsthe fallback policy, so a route added later is closed until it is markedAllowAnonymous(). A request with no registered credential is answered 401, including one to a path no route serves. - Each caller is told apart. A backend that runs less-trusted workers (agents, plugins, helper
processes) beside an owner-facing shell issues each worker its own credential, tied to a kind and
optionally a subject:
credentials.Issue("agent-session", sessionId). A route admits only the kinds it names (RequireCaller("owner"), 403 otherwise), and a handler readscontext.User.LoopbackCaller().Revokestops a credential when its worker is done. Credentials live in memory only. A presented credential is looked up by its SHA-256 digest, so the time a lookup takes says nothing about how close a guess was. - Only this computer's names are answered.
UseLoopbackHostCheckanswers 400 when theHostheader is not127.0.0.1,localhostor[::1]with the port the request came in on. Optionally it also accepts names underlocalhost, which browsers resolve to this computer themselves. A web page whose own name was pointed at 127.0.0.1 (DNS rebinding) is refused even on an open route. - Failures don't leak.
UseFaultsreports an unexpected failure as its exception type and the frames in the app's own code it passed through, innermost first ({"fault":{"type","at","frames"}}). It never includes the message, which can quote the data the request was about.Fault.Ofreads a failure away from any request the same way. On the Rust side,Response::faultreads that answer as aFault.
The names are the app's: the variable, the line's prefix, the file's path and the kinds.
using TauriKit.Sidecar.Loopback;
var credentials = new LoopbackCredentials();
var owner = credentials.Issue("owner");
var builder = LoopbackHost.CreateSlimBuilder(args);
builder.Services.AddLoopbackAuthentication(credentials);
var app = builder.Build();
app.UseLoopbackHostCheck();
app.UseFaults(new FaultOptions
{
OwnNamespaces = ["MyCompany."],
StatusFor = e => e is KeyNotFoundException ? StatusCodes.Status404NotFound : null,
});
app.MapGet("/health", () => "ok").AllowAnonymous();
app.MapPost("/settings", SaveSettings).RequireCaller("owner");
app.MapPost("/sessions", (HttpContext context) =>
{
// A worker gets its own credential in its environment, never the owner's.
var session = Guid.NewGuid().ToString("N");
return new { session, token = credentials.Issue("agent-session", session) };
}).RequireCaller("owner");
await app.RunPublishingAsync(Path.Combine(stateFolder, "run", "backend.json"), owner);
A backend started as a child registers the token its parent passed instead:
var token = LoopbackHost.ReadToken("HELPER_TOKEN");
if (token is null)
{
Console.Error.WriteLine("HELPER_TOKEN (32+ characters) is required");
return 2;
}
var credentials = new LoopbackCredentials();
credentials.Register(token, "app");
// … the same builder and routes …
await app.RunAnnouncingAsync("helper ready port=");
The library is compatible with ahead-of-time compilation, so a backend published with PublishAot
can use it. Tests can host the same pipeline with CreateSlimBuilder(args) and StartAsync, and
reach it over HttpClient at app.Urls.
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TauriKit.Sidecar.Loopback:
| Package | Downloads |
|---|---|
|
TauriKit.Sidecar.Loopback.AspNetCore
The ASP.NET Core host of a desktop app's loopback backend: listen on 127.0.0.1 only, announce the port the system picked or publish it in an owner-only discovery file, answer only registered callers (open routes by name), refuse non-loopback Host names, report unexpected failures without their messages, take a request to quit, and quit when the app that started it is gone. Pairs with the tauri-kit-sidecar crate's loopback feature. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.24.0 | 50 | 10/20/2026 |
| 0.23.0 | 119 | 10/19/2026 |
| 0.22.0 | 136 | 10/18/2026 |
| 0.21.0 | 124 | 10/17/2026 |
| 0.20.0 | 101 | 10/17/2026 |
| 0.19.0 | 106 | 10/16/2026 |
| 0.18.0 | 173 | 10/15/2026 |
| 0.17.0 | 103 | 10/15/2026 |
| 0.16.1 | 108 | 10/14/2026 |
| 0.16.0 | 186 | 10/10/2026 |
| 0.15.0 | 136 | 10/10/2026 |
| 0.14.0 | 106 | 10/9/2026 |
| 0.13.0 | 95 | 10/9/2026 |
| 0.12.1 | 91 | 10/8/2026 |
| 0.12.0 | 184 | 10/3/2026 |
| 0.11.0 | 121 | 10/2/2026 |
| 0.10.0 | 122 | 10/1/2026 |
| 0.9.1 | 96 | 10/1/2026 |
| 0.9.0 | 91 | 10/1/2026 |
| 0.8.0 | 94 | 10/1/2026 |