streamby-core 0.24.4 → 0.24.5
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/cors.js
CHANGED
|
@@ -18,19 +18,20 @@ const projectOriginMiddleware = async (req, res, next) => {
|
|
|
18
18
|
return res.status(404).json({ message: 'Project not found' });
|
|
19
19
|
}
|
|
20
20
|
if (project.allowedOrigin && project.allowedOrigin.length > 0) {
|
|
21
|
-
if (
|
|
21
|
+
// Allow if public ('*') or origin is in the list
|
|
22
|
+
if (project.allowedOrigin.includes('*') || project.allowedOrigin.includes(origin)) {
|
|
22
23
|
res.header('Access-Control-Allow-Origin', origin);
|
|
23
24
|
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
24
25
|
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
25
|
-
next();
|
|
26
|
+
return next();
|
|
26
27
|
}
|
|
27
28
|
else {
|
|
28
29
|
return res.status(403).json({ message: 'Origin not allowed' });
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
else {
|
|
32
|
-
// If
|
|
33
|
-
|
|
33
|
+
// If allowedOrigin is empty, deny access for security.
|
|
34
|
+
return res.status(403).json({ message: 'Origin not allowed' });
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
catch (error) {
|
|
@@ -157,8 +157,18 @@ function exportRouter(config) {
|
|
|
157
157
|
return res.status(404).json({ message: 'Export not found in this project' });
|
|
158
158
|
}
|
|
159
159
|
const origin = req.headers.origin;
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
let effectiveAllowedOrigins = exportMetadata.allowedOrigin;
|
|
161
|
+
// If export's allowedOrigin is ['*'] or it's not set, use the project's settings.
|
|
162
|
+
if (!effectiveAllowedOrigins || (effectiveAllowedOrigins.length === 1 && effectiveAllowedOrigins[0] === '*')) {
|
|
163
|
+
effectiveAllowedOrigins = project.allowedOrigin;
|
|
164
|
+
}
|
|
165
|
+
// If there's no origin, deny access unless it's public.
|
|
166
|
+
if (!origin && !(effectiveAllowedOrigins && effectiveAllowedOrigins.includes('*'))) {
|
|
167
|
+
return res.status(403).json({ message: 'Origin header required' });
|
|
168
|
+
}
|
|
169
|
+
// Check for public access ('*') or if the origin is in the list.
|
|
170
|
+
const isAllowed = effectiveAllowedOrigins && (effectiveAllowedOrigins.includes('*') || (origin && effectiveAllowedOrigins.includes(origin)));
|
|
171
|
+
if (!isAllowed) {
|
|
162
172
|
return res.status(403).json({ message: 'Unauthorized' });
|
|
163
173
|
}
|
|
164
174
|
const targetDb = config.databases?.find(db => db.type === project.dbType);
|