Skip to content
Open
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
26 changes: 14 additions & 12 deletions src/server/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,20 @@ function isTrustedAdminOrigin(origin: string | undefined, host: string | undefin
if (!origin) return true; // non-browser client (curl, CLI UI) on a trusted Host
try {
const parsed = new URL(origin);
// #3513 (desktop variant): the dsh desktop Electron app renders its
// settings pane from the custom scheme origin dsh-app://app, not an
// http origin. Browsers set the Origin header themselves — page
// content cannot forge it — and the dsh-app scheme exists only inside
// the dsh Electron app (a registered custom protocol), so a website
// can never produce a request whose Origin is dsh-app://. Accepting
// that exact origin (scheme dsh-app, hostname "app") admits the
// desktop embed probe without weakening the anti-rebinding property:
// rebinding attacks arrive with http/https attacker hostnames and
// still fail the hostname check below. Any other custom scheme or a
// different dsh-app hostname stays rejected.
if (parsed.protocol === "dsh-app:") {
// #3513/#5203 (desktop variant): the dsh desktop Electron app renders
// its settings pane from a custom scheme origin, not an http origin —
// dsh-app://app on older builds, dsh-desktop://app from DSH Desktop
// 0.13.0 onward (renderer flags --standard-schemes/--cors-schemes/
// --fetch-schemes=dsh-desktop). Browsers set the Origin header
// themselves — page content cannot forge it — and each scheme exists
// only inside the dsh Electron app (a registered custom protocol), so
// a website can never produce a request whose Origin uses one of them.
// Accepting exactly those origins (hostname "app") admits the desktop
// embed probe without weakening the anti-rebinding property: rebinding
// attacks arrive with http/https attacker hostnames and still fail the
// hostname check below. Any other custom scheme or a different
// hostname under these schemes stays rejected.
if (parsed.protocol === "dsh-app:" || parsed.protocol === "dsh-desktop:") {
return normalizeAdminHostname(parsed.hostname) === "app";
}
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return false;
Expand Down
29 changes: 17 additions & 12 deletions tests/dsh-panel-embed-cors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,24 @@ test("embed face echoes access-control-allow-origin for cross-origin pane probes
const spoofed = await request(actualPort, { host: trusted, origin: "http://evil.com:8080" });
assert.equal(spoofed.status, 403, "non-loopback Origin must still be rejected");

// #3513 (desktop variant): the dsh desktop Electron app renders the
// pane from the custom scheme origin dsh-app://app. The gate must
// admit exactly that origin so the probe's cors read carries the echo
// (real-world console: "blocked by CORS policy … from origin
// 'dsh-app://app'" with a bare 403).
const desktop = await request(actualPort, { host: trusted, origin: "dsh-app://app" });
assert.equal(desktop.status, 200, "dsh-app://app pane probe must be admitted");
assert.equal(desktop.acao, "dsh-app://app", "desktop scheme origin must be echoed verbatim");
// #3513/#5203 (desktop variant): the dsh desktop Electron app renders
// the pane from a custom scheme origin. Older builds use dsh-app://app;
// DSH Desktop 0.13.0 renamed the registered protocol to dsh-desktop
// (renderer flags --standard-schemes/--cors-schemes/--fetch-schemes=
// dsh-desktop), so its probe carries Origin dsh-desktop://app (#5203:
// panel stuck on "Failed to fetch" — bare 403, cors read rejected).
// The gate must admit exactly those origins so the probe's cors read
// carries the echo.
for (const [scheme, label] of [["dsh-app", "dsh-app"], ["dsh-desktop", "dsh-desktop"]] as const) {
const desktop = await request(actualPort, { host: trusted, origin: `${scheme}://app` });
assert.equal(desktop.status, 200, `${label}://app pane probe must be admitted`);
assert.equal(desktop.acao, `${scheme}://app`, `${label} scheme origin must be echoed verbatim`);
const desktopEvil = await request(actualPort, { host: trusted, origin: `${scheme}://evil` });
assert.equal(desktopEvil.status, 403, `${label} with a foreign hostname must be rejected`);
}

// The allowance is the dsh desktop convention ONLY: a foreign hostname
// under the same scheme, or any other custom scheme, stays rejected.
const desktopEvil = await request(actualPort, { host: trusted, origin: "dsh-app://evil" });
assert.equal(desktopEvil.status, 403, "dsh-app with a foreign hostname must be rejected");
// The allowance is the dsh desktop convention ONLY: any other custom
// scheme stays rejected.
const fileLike = await request(actualPort, { host: trusted, origin: "file://" });
assert.equal(fileLike.status, 403, "other non-http schemes stay rejected");
} finally {
Expand Down
Loading