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.
@@ -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
- const origin = req.headers.origin;
299
- let effectiveAllowedOrigins = exportMetadata.allowedOrigin;
300
- const projectOrigins = project.allowedOrigin;
301
- // If export's allowedOrigin is ['*'] or it's not set, it inherits from the project.
302
- if (!effectiveAllowedOrigins || (effectiveAllowedOrigins.length === 1 && effectiveAllowedOrigins[0] === '*')) {
303
- effectiveAllowedOrigins = projectOrigins;
304
- }
305
- else {
306
- // If the export has its own list, ensure it's a subset of the project's list (if project is not public).
307
- if (projectOrigins && !projectOrigins.includes('*')) {
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
- // Dev mode: auto-allow localhost requests on configured ports.
315
- let devModeAllowed = false;
316
- if (exportMetadata.devMode && origin) {
317
- const match = origin.match(/^https?:\/\/localhost:(\d+)$/);
318
- if (match) {
319
- const port = parseInt(match[1]);
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
- if (!devModeAllowed) {
332
- // If there's no origin header, deny access unless the effective scope is public.
333
- if (!origin && !(effectiveAllowedOrigins && effectiveAllowedOrigins.includes('*'))) {
334
- return res.status(403).json({ message: 'Origin header required' });
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
- // Check for public access ('*') or if the request's origin is in the effective list.
337
- const isAllowed = effectiveAllowedOrigins && (effectiveAllowedOrigins.includes('*') || (origin && effectiveAllowedOrigins.includes(origin)));
338
- if (!isAllowed) {
339
- return res.status(403).json({ message: 'Unauthorized' });
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamby-core",
3
- "version": "0.28.0",
3
+ "version": "0.28.1",
4
4
  "description": "StreamBy middleware framework for media storage management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",