@vulkano/core 1.8.0 → 1.8.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/bootstrap/server.js +27 -6
- package/package.json +1 -1
package/bootstrap/server.js
CHANGED
|
@@ -272,14 +272,35 @@ module.exports = function loadServer() {
|
|
|
272
272
|
rules: cspRules
|
|
273
273
|
} = expressConfig.csp || {};
|
|
274
274
|
|
|
275
|
-
if (cspEnabled) {
|
|
275
|
+
if (cspEnabled && cspRules) {
|
|
276
|
+
|
|
277
|
+
const cspRulesHeader = [];
|
|
278
|
+
|
|
279
|
+
if (Array.isArray(cspRules) && cspRules.length > 0) {
|
|
280
|
+
|
|
281
|
+
for ( let i = 0; i < cspRules.length; i += 1) {
|
|
282
|
+
cspRulesHeader.push(cspRules[i]);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
} else if (typeof cspRules === 'object') {
|
|
286
|
+
|
|
287
|
+
Object.keys(cspRules).forEach( (r) => {
|
|
288
|
+
const tmpValues = cspRules[r];
|
|
289
|
+
if (Array.isArray(tmpValues)) {
|
|
290
|
+
cspRulesHeader.push(`${r} ${tmpValues.join(' ')}`);
|
|
291
|
+
} else if (typeof tmpValues === 'string') {
|
|
292
|
+
cspRulesHeader.push(`${r} ${tmpValues}`);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
} else if (typeof cspRules === 'string') {
|
|
297
|
+
|
|
298
|
+
cspRulesHeader.push(cspRules);
|
|
276
299
|
|
|
277
|
-
if (!Array.isArray(cspRules)) {
|
|
278
|
-
console.error('Vulkano Error: ', 'The Content Security Policy Rules must be an array');
|
|
279
|
-
return;
|
|
280
300
|
}
|
|
281
301
|
|
|
282
|
-
|
|
302
|
+
// Has Rules
|
|
303
|
+
if (cspRulesHeader.length > 0) {
|
|
283
304
|
|
|
284
305
|
vulkano.use( (req, res, next) => {
|
|
285
306
|
|
|
@@ -287,7 +308,7 @@ module.exports = function loadServer() {
|
|
|
287
308
|
res.setHeader('Report-To', JSON.stringify(cspReportTo));
|
|
288
309
|
}
|
|
289
310
|
|
|
290
|
-
res.setHeader('Content-Security-Policy',
|
|
311
|
+
res.setHeader('Content-Security-Policy', cspRulesHeader.join('; '));
|
|
291
312
|
|
|
292
313
|
next();
|
|
293
314
|
|