Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion apps/server/src/device/DeviceHubProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ const fixture = (
) => {
let finalized = 0;
const requests: string[] = [];
const headers: Array<Record<string, string>> = [];
const client = HttpClient.make((request, _url, signal) =>
Effect.gen(function* () {
requests.push(request.url);
headers.push(request.headers);
signal.addEventListener("abort", () => {
finalized++;
});
Expand Down Expand Up @@ -61,7 +63,7 @@ const fixture = (
{ disableLogger: true },
);
disposers.push(dispose);
return { handler, requests, finalized: () => finalized };
return { handler, requests, headers, finalized: () => finalized };
};

describe("device hub proxy", () => {
Expand Down Expand Up @@ -131,6 +133,24 @@ describe("device hub proxy", () => {
]);
});

it("presents a remote browser's screenshot to the hub as a same-origin loopback request", async () => {
const { handler, headers } = fixture([AuthOrchestrationReadScope]);
const response = await handler(
new Request(
"http://t3.test/api/device-hub/vendor/serve-emu/api/screenshot?device=emulator-5554",
{
method: "POST",
headers: { origin: "https://devbox.tailnet.ts.net", "x-forwarded-proto": "https" },
},
),
);
expect(response.status).toBe(200);
await response.text();
expect(headers).toHaveLength(1);
expect(headers[0]).toMatchObject({ origin: "http://hub.test" });
expect(headers[0]).not.toHaveProperty("x-forwarded-proto");
});

it("never forwards the vendor shell endpoint", async () => {
const { handler, requests } = fixture([AuthOrchestrationOperateScope]);
expect(
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/device/DeviceHubProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ const DROPPED_REQUEST_HEADERS = new Set([
"dpop",
"content-length",
"accept-encoding",
// expo-device-hub takes the request origin from X-Forwarded-Proto, so a
// client's `https` fails serve-emu's Origin check.
"x-forwarded-proto",
]);

const isWebSocketUpgrade = (request: HttpServerRequest.HttpServerRequest) =>
Expand Down
Loading