mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
* fix(cli): play and present answer unknown paths with an inert refusal (SECOPS-2642 part 3) An OAuth return that lands on the play or present port was a 404 document on the same origin as the composition frame, so project script could read its ?code=&state= through a frame, a popup or the authorize redirect. Unknown paths, missing composition files and any request carrying code or state now get a fixed text/plain 404 on an opaque origin (CSP sandbox) that cannot be framed and drops its opener (COOP same-origin). play's app setup moves into an exported buildPlayApp so tests can serve it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): trim the inert refusal's comments to the package share Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import type { Hono } from "hono";
|
|
|
|
// Opaque origin, unframeable, opener dropped: same-origin project script cannot read a `?code=` return.
|
|
const OAUTH_RETURN_PARAMS = ["code", "state"] as const;
|
|
|
|
export const INERT_REFUSAL_HEADERS = {
|
|
"Content-Type": "text/plain; charset=utf-8",
|
|
"X-Content-Type-Options": "nosniff",
|
|
"Cache-Control": "no-store",
|
|
"Referrer-Policy": "no-referrer",
|
|
"Cross-Origin-Opener-Policy": "same-origin",
|
|
"Content-Security-Policy": "sandbox; default-src 'none'; frame-ancestors 'none'",
|
|
"X-Frame-Options": "DENY",
|
|
} as const;
|
|
|
|
function inertRefusal(): Response {
|
|
return new Response("Not found", { status: 404, headers: INERT_REFUSAL_HEADERS });
|
|
}
|
|
|
|
function carriesOAuthReturn(url: string): boolean {
|
|
const params = new URL(url).searchParams;
|
|
return OAUTH_RETURN_PARAMS.some((name) => params.has(name));
|
|
}
|
|
|
|
/** Register before any other middleware: the refusal replaces whatever headers the others add. */
|
|
export function refuseStrayRequestsInertly(app: Hono): void {
|
|
app.use(async function refuseStrayRequest(c, next) {
|
|
if (carriesOAuthReturn(c.req.url)) return inertRefusal();
|
|
await next();
|
|
if (c.res.status !== 404) return;
|
|
// Clear first: assigning over an existing response would carry its headers across.
|
|
c.res = undefined;
|
|
c.res = inertRefusal();
|
|
});
|
|
}
|