🎥 Make videos programmatically with React
`@remotion/studio`: Better protect handleAddAsset() endpoint
Jonny Burgerd3cd48c942d3
diff --git a/packages/studio-server/src/routes.ts b/packages/studio-server/src/routes.tsindex 199364cce5..39ed683973 100644--- a/packages/studio-server/src/routes.ts+++ b/packages/studio-server/src/routes.ts@@ -219,6 +219,16 @@ const handleAddAsset = ({publicDir: string;}): Promise<void> => {try {+ const origin = req.headers.origin;+ const host = req.headers.host;++ if (origin) {+ const originUrl = new URL(origin);+ if (originUrl.host !== host) {+ throw new Error('Request from different origin not allowed');+ }+ }+const query = new URLSearchParams(search);const filePath = query.get('filePath');@@ -366,7 +376,7 @@ export const handleRoutes = ({return handleOpenInEditor(remotionRoot, request, response, logLevel);}- if (url.pathname === '/api/add-asset') {+ if (url.pathname === `${staticHash}/api/add-asset`) {return handleAddAsset({req: request,res: response,diff --git a/packages/studio/src/api/write-static-file.ts b/packages/studio/src/api/write-static-file.tsindex 6c56075f71..78dfb15b24 100644--- a/packages/studio/src/api/write-static-file.ts+++ b/packages/studio/src/api/write-static-file.ts@@ -9,7 +9,10 @@ export const writeStaticFile = async ({throw new Error('writeStaticFile() is not available in read-only Studio');}- const url = new URL('/api/add-asset', window.location.origin);+ const url = new URL(+ `${window.remotion_staticBase}/api/add-asset`,+ window.location.origin,+ );if (filePath.includes('\\')) {return Promise.reject(new Error('File path cannot contain backslashes'));