csp: allow multiple lines and add presets
This commit is contained in:
@@ -477,6 +477,12 @@ async function removeDashboardConfig(subdomain, domain) {
|
||||
await reload();
|
||||
}
|
||||
|
||||
function normalizeCSP(csp) {
|
||||
const lines = csp.split('\n').map(line => line.trim()).filter(line => line && !line.startsWith('#'));
|
||||
const statements = lines.map(line => line.endsWith(';') ? line : `${line};`); // semicolon terminate all lines
|
||||
return statements.join(' ').replace(/\s+/g, ' ').trim(); // merge into single line
|
||||
}
|
||||
|
||||
async function writeAppLocationNginxConfig(app, location, certificatePath) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof location, 'object');
|
||||
@@ -514,7 +520,7 @@ async function writeAppLocationNginxConfig(app, location, certificatePath) {
|
||||
const reverseProxyConfig = app.reverseProxyConfig || {}; // some of our code uses fake app objects
|
||||
if (reverseProxyConfig.robotsTxt) data.robotsTxtQuoted = JSON.stringify(app.reverseProxyConfig.robotsTxt);
|
||||
if (reverseProxyConfig.csp) {
|
||||
data.cspQuoted = `"${app.reverseProxyConfig.csp}"`;
|
||||
data.cspQuoted = `"${normalizeCSP(app.reverseProxyConfig.csp)}"`;
|
||||
data.hideHeaders = [ 'Content-Security-Policy' ];
|
||||
if (reverseProxyConfig.csp.includes('frame-ancestors ')) data.hideHeaders.push('X-Frame-Options');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user