fix: initialize hosted Studio behind HTTPS reverse proxies
This commit is contained in:
1 parent
60467a4c05
commit
953e928b05
9 files changed
+186
-4
No files matched your search
@@ -56,6 +56,28 @@ try {
|
||||
const application = await (
|
||||
await fetch(origin + "/design-studio/api/application")
|
||||
).json();
|
||||
// Browser module requests carry Origin; the VM forwards them over plain HTTP.
|
||||
const publicOrigin =
|
||||
process.env.STUDIO_PUBLIC_ORIGIN ?? "https://component.wrnexusjs.dev";
|
||||
const proxiedHeaders = {
|
||||
origin: publicOrigin,
|
||||
host: new URL(publicOrigin).host,
|
||||
};
|
||||
for (const path of [
|
||||
"/design-studio/studio.js",
|
||||
"/design-studio/api/application",
|
||||
]) {
|
||||
const proxied = await fetch(origin + path, { headers: proxiedHeaders });
|
||||
if (!proxied.ok)
|
||||
throw Error(
|
||||
`HTTPS-origin request over HTTP failed: ${path} (${proxied.status})`,
|
||||
);
|
||||
}
|
||||
const rejected = await fetch(origin + "/design-studio/studio.js", {
|
||||
headers: { ...proxiedHeaders, origin: "https://attacker.example" },
|
||||
});
|
||||
if (rejected.status !== 403)
|
||||
throw Error("Cross-origin Studio requests were not rejected.");
|
||||
const generation = await (
|
||||
await fetch(origin + "/design-studio/api/generation")
|
||||
).json();
|
||||
|
||||
Reference in new issue
Block a user