streamby-core 0.24.4 → 0.24.6
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,28 @@ 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
|
+
const projectOrigins = project.allowedOrigin;
|
|
162
|
+
// If export's allowedOrigin is ['*'] or it's not set, it inherits from the project.
|
|
163
|
+
if (!effectiveAllowedOrigins || (effectiveAllowedOrigins.length === 1 && effectiveAllowedOrigins[0] === '*')) {
|
|
164
|
+
effectiveAllowedOrigins = projectOrigins;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
// If the export has its own list, ensure it's a subset of the project's list (if project is not public).
|
|
168
|
+
if (projectOrigins && !projectOrigins.includes('*')) {
|
|
169
|
+
const isSubset = effectiveAllowedOrigins.every((o) => projectOrigins.includes(o));
|
|
170
|
+
if (!isSubset) {
|
|
171
|
+
return res.status(403).json({ message: 'Unauthorized: Export origins are not allowed by the parent project.' });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// If there's no origin header, deny access unless the effective scope is public.
|
|
176
|
+
if (!origin && !(effectiveAllowedOrigins && effectiveAllowedOrigins.includes('*'))) {
|
|
177
|
+
return res.status(403).json({ message: 'Origin header required' });
|
|
178
|
+
}
|
|
179
|
+
// Check for public access ('*') or if the request's origin is in the effective list.
|
|
180
|
+
const isAllowed = effectiveAllowedOrigins && (effectiveAllowedOrigins.includes('*') || (origin && effectiveAllowedOrigins.includes(origin)));
|
|
181
|
+
if (!isAllowed) {
|
|
162
182
|
return res.status(403).json({ message: 'Unauthorized' });
|
|
163
183
|
}
|
|
164
184
|
const targetDb = config.databases?.find(db => db.type === project.dbType);
|