Skip to content

Commit b25db21

Browse files
committed
Refactor SimDeck auth and unblock native API handlers
1 parent d7c2033 commit b25db21

18 files changed

Lines changed: 623 additions & 103 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ To focus a specific simulator, open
6363
The Rust server exposes HTTP on the requested port and WebTransport on `port + 1`.
6464
The browser bootstrap comes from `GET /api/health`, which returns the WebTransport URL template,
6565
certificate hash, and packet version needed by the client.
66+
The served browser UI receives the generated API access token automatically; direct HTTP callers can use the startup token with `X-SimDeck-Token` or `Authorization: Bearer`.
6667

6768
## Service
6869

docs/api/health.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Returns the static bootstrap information the browser client needs to open a WebT
1414
"timestamp": 1714094761.234,
1515
"videoCodec": "hevc",
1616
"webTransport": {
17-
"urlTemplate": "https://127.0.0.1:4311/wt/simulators/{udid}",
17+
"urlTemplate": "https://127.0.0.1:4311/wt/simulators/{udid}?simdeckToken=...",
1818
"certificateHash": {
1919
"algorithm": "sha-256",
2020
"value": "3f...e9"
@@ -30,11 +30,11 @@ Returns the static bootstrap information the browser client needs to open a WebT
3030
| `httpPort` / `wtPort` | Numeric ports for the HTTP and WebTransport servers. WebTransport is always `httpPort + 1`. |
3131
| `timestamp` | Server-side `time.now()` as a fractional Unix epoch in seconds. |
3232
| `videoCodec` | Active encoder. One of `hevc`, `h264`, `h264-software`. See [Video Pipeline](/guide/video). |
33-
| `webTransport.urlTemplate` | URL with a `{udid}` placeholder for the simulator stream. Substitute and dial. |
33+
| `webTransport.urlTemplate` | URL with a `{udid}` placeholder and access token query for the simulator stream. |
3434
| `webTransport.certificateHash.value` | SHA-256 of the server's self-signed cert. Pin via `serverCertificateHashes` in the WT client. |
3535
| `webTransport.packetVersion` | The current binary packet protocol version. Clients should refuse to parse unknown versions. |
3636

37-
The certificate is regenerated every time the server restarts. A client that caches the hash should refetch `/api/health` after any disconnection.
37+
The certificate and default access token are regenerated every time the server restarts. A client that caches the hash should refetch `/api/health` after any disconnection.
3838

3939
## `GET /api/metrics`
4040

docs/api/rest.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# REST Endpoints
22

3-
The SimDeck server exposes one REST API over plain HTTP. Every route lives under `/api/`. Responses are JSON unless explicitly noted otherwise. Errors return a JSON body with `{"error": {"message": "..."}}` and an appropriate HTTP status.
3+
The SimDeck server exposes one REST API over plain HTTP. Every route lives under `/api/`. Responses are JSON unless explicitly noted otherwise. Errors return a JSON body with `{"error": "..."}` and an appropriate HTTP status.
44

5-
CORS is wide open (`Access-Control-Allow-Origin: *`) so you can call the API from any browser tab on the same network.
5+
The served browser UI receives the generated access token automatically through a strict same-site cookie. Direct API callers must send `X-SimDeck-Token: <token>` or `Authorization: Bearer <token>`.
66

77
## Conventions
88

@@ -25,7 +25,7 @@ Returns server health, the WebTransport URL template, and the certificate hash t
2525
"timestamp": 1714094761.234,
2626
"videoCodec": "hevc",
2727
"webTransport": {
28-
"urlTemplate": "https://127.0.0.1:4311/wt/simulators/{udid}",
28+
"urlTemplate": "https://127.0.0.1:4311/wt/simulators/{udid}?simdeckToken=...",
2929
"certificateHash": {
3030
"algorithm": "sha-256",
3131
"value": "3f...e9"

docs/api/webtransport.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ Live video and the per-session control handshake travel over WebTransport. The h
77
The exact URL is reported by `GET /api/health`. The template looks like:
88

99
```text
10-
https://<advertise-host>:<wt-port>/wt/simulators/{udid}
10+
https://<advertise-host>:<wt-port>/wt/simulators/{udid}?simdeckToken=<token>
1111
```
1212

13-
Replace `{udid}` with the simulator UDID from `GET /api/simulators`.
13+
Replace `{udid}` with the simulator UDID from `GET /api/simulators`. The `simdeckToken` query parameter is included in the authenticated `/api/health` response and is required by the WebTransport server.
1414

1515
## Certificate pinning
1616

docs/cli/commands.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Start the HTTP and WebTransport servers in the foreground. This is the only comm
99
```sh
1010
simdeck serve [--port <u16>] [--bind <ip>] [--advertise-host <host>]
1111
[--client-root <path>] [--video-codec <codec>]
12+
[--access-token <token>]
1213
```
1314

1415
| Flag | Default | Description |
@@ -18,13 +19,15 @@ simdeck serve [--port <u16>] [--bind <ip>] [--advertise-host <host>]
1819
| `--advertise-host` | matches `--bind` | Hostname or IP advertised to remote clients in the WebTransport URL template and cert. |
1920
| `--client-root` | bundled `client/dist` | Override the static client directory. |
2021
| `--video-codec` | `hevc` | One of `hevc`, `h264`, `h264-software`. See [Video Pipeline](/guide/video). |
22+
| `--access-token` | generated at startup | Token accepted by `X-SimDeck-Token`, `Authorization: Bearer`, or the served UI cookie. |
2123

2224
When the server is up it prints something like:
2325

2426
```text
2527
HTTP listening on http://127.0.0.1:4310
2628
WebTransport listening on https://127.0.0.1:4311/wt/simulators/{udid}
2729
Serving client from /usr/local/lib/node_modules/simdeck/client/dist
30+
API access token: 9f...
2831
```
2932

3033
`Ctrl-C` shuts both servers down cleanly.
@@ -36,6 +39,7 @@ Install SimDeck as a per-user `launchd` service. Same flags as `serve`:
3639
```sh
3740
simdeck service on [--port <u16>] [--bind <ip>] [--advertise-host <host>]
3841
[--client-root <path>] [--video-codec <codec>]
42+
[--access-token <token>]
3943
```
4044

4145
The command writes `~/Library/LaunchAgents/dev.nativescript.simdeck.plist`, bootstraps it into `gui/<uid>`, and immediately kickstarts it. See [Background Service](/guide/service) for details.

docs/cli/flags.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ Override the static client directory. The Rust server serves the contents at the
6767

6868
Encoder used by the native bridge. See [Video Pipeline](/guide/video) for when to switch.
6969

70+
### `--access-token <token>`
71+
72+
| Default | generated at startup |
73+
| ------- | -------------------- |
74+
| Type | string |
75+
76+
HTTP API and WebTransport access token. The served browser UI receives it automatically through a strict same-site cookie, so normal local use does not require copying the token. Direct API callers should send either `X-SimDeck-Token: <token>` or `Authorization: Bearer <token>`.
77+
7078
## Positional arguments
7179

7280
Subcommands that take positionals expect them in the order shown:

docs/extensions/browser-client.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ The browser client is designed to live inside any container that can host a webv
103103

104104
1. Point the host at `http://<simdeck-host>:<port>/`.
105105
2. Allow the host to talk to the same WebTransport endpoint exposed by the server.
106-
3. Optionally, gate the host behind your own auth — SimDeck assumes a trusted local network.
106+
3. For direct API calls outside the served origin, pass the SimDeck access token with `X-SimDeck-Token` or `Authorization: Bearer`.

docs/guide/lan-access.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The server generates a fresh self-signed certificate every time it starts. The c
5656
"wtPort": 4311,
5757
"videoCodec": "hevc",
5858
"webTransport": {
59-
"urlTemplate": "https://192.168.1.50:4311/wt/simulators/{udid}",
59+
"urlTemplate": "https://192.168.1.50:4311/wt/simulators/{udid}?simdeckToken=...",
6060
"certificateHash": {
6161
"algorithm": "sha-256",
6262
"value": "..."
@@ -72,16 +72,24 @@ Restarting the server invalidates the previous certificate. Open clients reconne
7272

7373
## Authentication and security
7474

75-
SimDeck assumes a trusted local network. The HTTP API has no built-in authentication and the WebTransport endpoint accepts any client that knows the URL.
75+
SimDeck generates an API access token at startup unless you pass `--access-token <token>`. The served browser UI receives the token automatically through a strict same-site cookie, so opening `http://<advertise-host>:<port>` remains seamless.
76+
77+
Direct API callers must send one of:
78+
79+
```text
80+
X-SimDeck-Token: <token>
81+
Authorization: Bearer <token>
82+
```
83+
84+
The WebTransport URL template returned by authenticated `GET /api/health` includes a `simdeckToken` query parameter for the browser stream worker.
7685

7786
Recommended practice for shared networks:
7887

7988
- Run SimDeck only on networks you control.
89+
- Use `--access-token <stable-secret>` for background services or scripted LAN access.
8090
- Combine with macOS Application Firewall to restrict inbound access to known peers.
8191
- For shared NativeScript inspectors, set an `authToken` when starting the [Swift in-app agent](/inspector/swift#auth-token) so app-side requests must include the token.
8292

83-
A roadmap item is to add an optional bearer-token header for the HTTP API and WebTransport `?token=` parameter. Until that lands, treat SimDeck like any unauthenticated dev tool.
84-
8593
## Quick checklist
8694

8795
To make a SimDeck server reachable from another device:

docs/guide/service.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ You can pass any of:
2121
| `--advertise-host` | matches `--bind` | Hostname advertised to remote clients. |
2222
| `--client-root` | bundled `client/dist` | Override the static client directory. |
2323
| `--video-codec` | `hevc` | One of `hevc`, `h264`, `h264-software`. See [Video](/guide/video). |
24+
| `--access-token` | generated at startup | Stable API token for direct HTTP/WebTransport integrations. |
2425

2526
The command:
2627

0 commit comments

Comments
 (0)