mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix(studio-server): refuse cross-origin writes and unknown hosts on the preview server (#7490)
* fix(studio-server): reject cross-origin state-changing requests Non-GET routes in createStudioApi answer 403 unless the shared sameOriginPost predicate (lifted into studio-server's ./request-identity subpath) accepts the request: the Host must be a server identity, a present Sec-Fetch-Site must be same-origin, and a present Origin must match the effective host and scheme. Hosts behind Codespaces or tunnels allow their public name with HYPERFRAMES_PREVIEW_ALLOWED_HOSTS, read by `hyperframes preview` and the Studio dev server. Squashed from #6128 (42574a7,110a300,89011e1,41c6626,27193bb) onto current main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): the preview server answers only the hosts it is reached by Every route of `hyperframes preview` (the forwarded studio API, the SSE stream, /__hyperframes_config and the Studio page) now answers only loopback names, the HYPERFRAMES_PREVIEW_HOST bind, or a host listed in HYPERFRAMES_PREVIEW_ALLOWED_HOSTS, the same list the write guard uses. Only the Host header counts here, since a page can set X-Forwarded-Host on its own requests and a read carries no Origin to compare it with. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Dextheking1 <Dextheking1@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
Dextheking1
parent
b4c7f9cf7c
commit
f318d3d08a
@@ -47,6 +47,29 @@ Studio reads the flag once, when its modules load, so set
|
||||
`window.__HF_STUDIO_ENV__` before loading Studio; the CLI injects it, but a host
|
||||
that mounts the API itself must inject it too.
|
||||
|
||||
The API is unauthenticated, so state-changing requests are checked against
|
||||
the request's own origin, scheme included: a write is accepted only when it
|
||||
comes from the Studio page this server serves. Loopback works with no setup.
|
||||
If you mount the API on a public host name (your own domain, a tunnel, a
|
||||
Codespaces address), name it in `allowedHosts` so writes from that origin
|
||||
pass:
|
||||
|
||||
```ts
|
||||
app.route(
|
||||
"/api",
|
||||
createStudioApi(adapter, { allowedHosts: ["studio.example.com"] }),
|
||||
);
|
||||
```
|
||||
|
||||
With `hyperframes preview` and the Studio dev server there is no code to
|
||||
change: both read the extra hosts from `HYPERFRAMES_PREVIEW_ALLOWED_HOSTS`
|
||||
(comma separated) and pass them as `allowedHosts`. A refused write answers
|
||||
403 with the refused host named and this variable as the fix:
|
||||
|
||||
```bash
|
||||
HYPERFRAMES_PREVIEW_ALLOWED_HOSTS=demo.tunnels.example hyperframes preview
|
||||
```
|
||||
|
||||
A `StudioApiAdapter` supplies:
|
||||
|
||||
- project listing and resolution;
|
||||
|
||||
Reference in New Issue
Block a user