streamby-core 0.28.1 → 0.28.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -295,51 +295,45 @@ function exportRouter(config) {
|
|
|
295
295
|
if (!exportMetadata) {
|
|
296
296
|
return res.status(404).json({ message: 'Export not found in this project' });
|
|
297
297
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
if (
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
// If the export has its own list, ensure it's a subset of the project's list (if project is not public).
|
|
311
|
-
if (projectOrigins && !projectOrigins.includes('*')) {
|
|
312
|
-
const isSubset = effectiveAllowedOrigins.every((o) => projectOrigins.includes(o));
|
|
313
|
-
if (!isSubset) {
|
|
314
|
-
return res.status(403).json({ message: 'Unauthorized: Export origins are not allowed by the parent project.' });
|
|
315
|
-
}
|
|
298
|
+
const origin = req.headers.origin;
|
|
299
|
+
let effectiveAllowedOrigins = exportMetadata.allowedOrigin;
|
|
300
|
+
const projectOrigins = project.allowedOrigin;
|
|
301
|
+
// If export's allowedOrigin is empty, ['*'], or not set, it inherits from the project.
|
|
302
|
+
if (!effectiveAllowedOrigins || effectiveAllowedOrigins.length === 0 || (effectiveAllowedOrigins.length === 1 && effectiveAllowedOrigins[0] === '*')) {
|
|
303
|
+
effectiveAllowedOrigins = projectOrigins;
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
if (projectOrigins && !projectOrigins.includes('*')) {
|
|
307
|
+
const isSubset = effectiveAllowedOrigins.every((o) => projectOrigins.includes(o));
|
|
308
|
+
if (!isSubset) {
|
|
309
|
+
return res.status(403).json({ message: 'Unauthorized: Export origins are not allowed by the parent project.' });
|
|
316
310
|
}
|
|
317
311
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
312
|
+
}
|
|
313
|
+
// Dev mode: auto-allow localhost requests on configured ports.
|
|
314
|
+
let devModeAllowed = false;
|
|
315
|
+
if (exportMetadata.devMode && origin) {
|
|
316
|
+
const match = origin.match(/^https?:\/\/localhost:(\d+)$/);
|
|
317
|
+
if (match) {
|
|
318
|
+
const port = parseInt(match[1]);
|
|
319
|
+
const allowedPorts = exportMetadata.devPorts?.length
|
|
320
|
+
? exportMetadata.devPorts
|
|
321
|
+
: [3000, 5173, 8080, 4200];
|
|
322
|
+
if (allowedPorts.includes(port)) {
|
|
323
|
+
devModeAllowed = true;
|
|
324
|
+
res.header('Access-Control-Allow-Origin', origin);
|
|
325
|
+
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
326
|
+
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
333
327
|
}
|
|
334
328
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
329
|
+
}
|
|
330
|
+
if (!devModeAllowed) {
|
|
331
|
+
if (!origin && !(effectiveAllowedOrigins && effectiveAllowedOrigins.includes('*'))) {
|
|
332
|
+
return res.status(403).json({ message: 'Origin header required' });
|
|
333
|
+
}
|
|
334
|
+
const isAllowed = effectiveAllowedOrigins && (effectiveAllowedOrigins.includes('*') || (origin && effectiveAllowedOrigins.includes(origin)));
|
|
335
|
+
if (!isAllowed) {
|
|
336
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
343
337
|
}
|
|
344
338
|
}
|
|
345
339
|
let data;
|