Concepts
How Klyroo. separates server-side credentials from user sessions, models browser and handoff lifecycles, handles idempotency and retries, authenticates incoming webhooks with zero-allocation HMAC-SHA256 verification, and achieves NativeAOT compatibility.
On this page
Server-side architecture and security boundary
Hotkey hosts persistent cloud browsers behind an HTTPS API (https://). Unlike the Blazor/MAUI UI libraries in Klyroo, Klyroo. is strictly a server-side library because every operation requires secret credentials (a bearer API key or a webhook signing secret):
Blazor / MAUI client (authenticated user)
|
| 1. Authenticated call to your app API (no Hotkey key on client)
v
Your .NET backend ----[2. HotkeyClient + Bearer key]----> Hotkey HTTP API
| |
| 3. Return expiring ask.Link / embed.Url |
v to authorized user only |
User completes step in Hotkey hosted view |
| |
|<---------[4. POST raw body + Hotkey-Signature]-------+
|
+-- 5. HotkeyWebhook.VerifyAndRead (HMAC-SHA256, ±300s)
+-- 6. Deduplicate on delivery.Id, verify browser ownership, resume workflowThree invariants protect this boundary:
- Ownership lives in your database. Your backend authenticates the user and maps their stable user ID (
ExternalId) toHotkeyBrowser.. Never trust a browser ID sent by a client without checking your ownership table.Id - Credentials never cross to the client. Workspace API keys, browser-scoped keys and webhook secrets stay in server configuration (
IConfiguration, environment variables, secret stores). - Clients only receive scoped, expiring URLs.
CreateAskAsyncreturns a one-time expiring handoff link (ask.);Link CreateEmbedAsyncreturns a short-lived origin-restricted embed URL (embed.).Url
Workspace keys vs browser-scoped keys
| Key type | Created by | Capabilities | Where it belongs |
|---|---|---|---|
| Workspace key | Hotkey console | Provision/delete browsers, configure workspace embed origins, manage webhook endpoints, read workspace usage | Provisioning service and admin backend only |
| Browser-scoped agent key | Create |
Operates on a single browser only; revocable independently via Revoke |
Per-user background workers or isolated automation jobs |
| Webhook signing secret | Create / console |
Authenticates incoming POST deliveries via Hotkey-Signature |
Webhook receiver endpoint only |
Keeping the workspace key out of worker processes limits blast radius if a single job or worker is compromised.
Idempotency and retry state machine
HotkeyClient serializes each JSON request body to UTF-8 bytes once before entering the retry loop, because Hotkey compares exact payload bytes when an Idempotency-Key is replayed.
| Operation class | Automatic retries | Retry triggers | Max delay waited |
|---|---|---|---|
Safe reads (GET) |
Up to 2 retries | ConnectionError, ResponseEnded, HTTP 429, 500, 502, 503, 504 |
30 seconds |
Idempotent mutations (POST/PATCH with idempotencyKey, or auto-generated per-call GUID) |
Up to 2 retries | Same as above + Hotkey error code idempotency_ |
30 seconds |
CreateEmbedAsync |
0 retries (sent once) | None — each call mints a fresh embed token | — |
DELETE calls (Delete, RevokeEmbedAsync, Revoke, etc.) |
0 retries (sent once) | None | — |
- Backoff calculation:
HotkeyClientrespects the HTTPRetry-Afterheader (delta or date) first, then the JSON error'sretry_field, falling back to linear backoff (after 1s,2s;250ms,500msfor connection drops). - 30-second ceiling: If Hotkey asks to wait longer than 30 seconds,
HotkeyClientthrowsHotkeyExceptionimmediately withRetryAfterpopulated so your web request thread is never stalled and a durable queue can reschedule the job. - Conflict recovery (
GetOr): CatchesCreate Browser Async 409 ConflictwhenCode == "browser_andexists" Existingis present, fetches that browser, and confirmsBrowserId existing.before returning it.External Id == settings. ExternalId
Signed webhook verification
HotkeyWebhook. authenticates the raw HTTP body before deserializing JSON:
- Header validation: Parses
Hotkey-Signaturestrictly ast=(rejecting extra suffixes, malformed hex, or overlong timestamps).<unix_ seconds>,v1= <64_ hex_ chars> - Replay window: Rejects timestamps outside ±300 seconds (5 minutes) around
now ?? Date.Time Offset. UtcNow - Constant-time HMAC-SHA256: Hashes
"using stack-allocated buffers for the timestamp prefix and standard-length secrets, zeroes secret bytes in a<timestamp>." + raw Body finallyblock (Cryptographic), and compares againstOperations. ZeroMemory v1withCryptographic.Operations. FixedTimeEquals - Source-generated deserialization: Deserializes
HotkeyEventwithHotkeyonly after authentication succeeds, and rejects events missing a non-emptyJson Context. Default. HotkeyEvent IdorType.
Because verification hashes the exact transmitted bytes, parsing and re-serializing JSON before calling VerifyAndRead will break the signature.
Transport hardening and credential hygiene
- Header injection protection: Both
apiKeyand caller-suppliedidempotencyKeyare validated to reject whitespace and ASCII control characters (\,r \,n < 0x21,0x7f). - Resource ID validation: Every resource identifier (
browserId,askId,embedId,downloadId,keyId,endpointId,signInId) is validated to contain only ASCII letters, digits,_and-before building request paths, eliminating path traversal or query smuggling. - Bounded error responses: Error bodies are read with a 64 KiB cap (
MaxError) so a misbehaving proxy returning a large HTML page cannot exhaust backend memory.Body Bytes - No redirects or cookies:
AddKlyrooHotkeyconfiguresSocketswithHttp Handler Allow(preventing bearer token leakage to a redirect target),Auto Redirect = false UseCookies = false,Pooled(safe DNS rotation),Connection Lifetime = 2 minutes ConnectandTimeout = 10 seconds MaxResponseKiB.Headers Length = 32 - Secret-safe models: Types carrying expiring links, embed tokens or secrets (
HotkeyAsk,HotkeyEmbed,HotkeyAgentKey,Hotkey) areWebhook Endpoint sealed classtypes rather thanrecordtypes, so compiler-generatedToString()never prints sensitive fields into structured logs.
Source-generated JSON and NativeAOT
All request and response types are serialized through a compile-time System. Json (Hotkey) with snake_ naming and null omission. Klyroo. uses zero runtime reflection and builds cleanly under IsTrimmable = true and IsAot.
Design decisions and trade-offs
- Server-side only, outside
Klyroo.. KeepingStack Klyroo.as an independently versioned server-side package avoids pulling API-credential workflows into browser or mobile clients and adds zero overhead to apps that do not need cloud browsers. The cost is one extra package reference and registration call when you adopt it.Hotkey - Sealed classes for secret-bearing payloads. Avoiding
recordonHotkeyAsk,HotkeyEmbed,HotkeyAgentKeyandHotkeyprevents accidental secret disclosure in logs. The trade-off is no compiler-synthesized value equality on those four types.Webhook Endpoint - Bounded retries with a 30-second ceiling. Retrying up to twice for short delays absorbs brief transient faults without tying up ASP.NET Core request threads on long rate limits.
- No automatic retry on
CreateEmbedAsync. Minting an embed creates a new token per request, so blind retries could issue untracked live-view tokens. - Raw-byte HMAC verification before JSON parsing. Hashing the exact HTTP body bytes avoids JSON canonicalization mismatches and blocks unauthenticated payloads before deserialization. The trade-off is buffering the request body stream in your webhook endpoint.