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
- // 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;
308
- }
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
- }
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
- // 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
- }
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
- 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
- }
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;
@@ -16,6 +16,8 @@ const resolveSubscription = async (auth) => {
16
16
  const ensureSubscription = async (req, res, next) => {
17
17
  try {
18
18
  const auth = req.auth;
19
+ if (!auth)
20
+ return next();
19
21
  const plan = await resolveSubscription(auth);
20
22
  req.subscription = plan;
21
23
  next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamby-core",
3
- "version": "0.28.1",
3
+ "version": "0.28.3",
4
4
  "description": "StreamBy middleware framework for media storage management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",