streamby-core 0.28.0 → 0.28.1
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.
- package/dist/middleware/routes/export.js +41 -38
- package/package.json +1 -1
|
@@ -295,48 +295,51 @@ 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
|
-
effectiveAllowedOrigins =
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
const isSubset = effectiveAllowedOrigins.every((o) => projectOrigins.includes(o));
|
|
309
|
-
if (!isSubset) {
|
|
310
|
-
return res.status(403).json({ message: 'Unauthorized: Export origins are not allowed by the parent project.' });
|
|
311
|
-
}
|
|
298
|
+
// Authenticated project members bypass origin checks (e.g. dev environments).
|
|
299
|
+
const auth = await config.authProvider(req).catch(() => null);
|
|
300
|
+
const isMember = auth?.userId && (0, auth_1.isProjectMember)(project, auth.userId);
|
|
301
|
+
if (!isMember) {
|
|
302
|
+
const origin = req.headers.origin;
|
|
303
|
+
let effectiveAllowedOrigins = exportMetadata.allowedOrigin;
|
|
304
|
+
const projectOrigins = project.allowedOrigin;
|
|
305
|
+
// If export's allowedOrigin is empty, ['*'], or not set, it inherits from the project.
|
|
306
|
+
if (!effectiveAllowedOrigins || effectiveAllowedOrigins.length === 0 || (effectiveAllowedOrigins.length === 1 && effectiveAllowedOrigins[0] === '*')) {
|
|
307
|
+
effectiveAllowedOrigins = projectOrigins;
|
|
312
308
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
const allowedPorts = exportMetadata.devPorts?.length
|
|
321
|
-
? exportMetadata.devPorts
|
|
322
|
-
: [3000, 5173, 8080, 4200];
|
|
323
|
-
if (allowedPorts.includes(port)) {
|
|
324
|
-
devModeAllowed = true;
|
|
325
|
-
res.header('Access-Control-Allow-Origin', origin);
|
|
326
|
-
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
327
|
-
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
309
|
+
else {
|
|
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
|
+
}
|
|
328
316
|
}
|
|
329
317
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
318
|
+
// Dev mode: auto-allow localhost requests on configured ports.
|
|
319
|
+
let devModeAllowed = false;
|
|
320
|
+
if (exportMetadata.devMode && origin) {
|
|
321
|
+
const match = origin.match(/^https?:\/\/localhost:(\d+)$/);
|
|
322
|
+
if (match) {
|
|
323
|
+
const port = parseInt(match[1]);
|
|
324
|
+
const allowedPorts = exportMetadata.devPorts?.length
|
|
325
|
+
? exportMetadata.devPorts
|
|
326
|
+
: [3000, 5173, 8080, 4200];
|
|
327
|
+
if (allowedPorts.includes(port)) {
|
|
328
|
+
devModeAllowed = true;
|
|
329
|
+
res.header('Access-Control-Allow-Origin', origin);
|
|
330
|
+
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
331
|
+
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
332
|
+
}
|
|
333
|
+
}
|
|
335
334
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
335
|
+
if (!devModeAllowed) {
|
|
336
|
+
if (!origin && !(effectiveAllowedOrigins && effectiveAllowedOrigins.includes('*'))) {
|
|
337
|
+
return res.status(403).json({ message: 'Origin header required' });
|
|
338
|
+
}
|
|
339
|
+
const isAllowed = effectiveAllowedOrigins && (effectiveAllowedOrigins.includes('*') || (origin && effectiveAllowedOrigins.includes(origin)));
|
|
340
|
+
if (!isAllowed) {
|
|
341
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
342
|
+
}
|
|
340
343
|
}
|
|
341
344
|
}
|
|
342
345
|
let data;
|