Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding "style-src 'unsafe-inline' 'self'" to default CSP rules #41305

Merged
merged 12 commits into from
Aug 9, 2019
Merged
Prev Previous commit
Next Next commit
Verifying all CSP responses
  • Loading branch information
kobelb committed Aug 6, 2019
commit c80b6b0fd988f96927d995537d5e40d9165e5a83
18 changes: 12 additions & 6 deletions test/api_integration/apis/general/csp.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,27 @@ export default function ({ getService }) {
const response = await supertest.get('/app/kibana');

expect(response.headers).to.have.property('content-security-policy');
});

it('csp header does not allow all inline scripts', async () => {
const response = await supertest.get('/app/kibana');

const header = response.headers['content-security-policy'];
const parsed = new Map(header.split(';').map(rule => {
const parts = rule.trim().split(' ');
const key = parts.splice(0, 1)[0];
return [key, parts];
}));

// ensure script-src uses a nonce, and remove it so we can .eql everything else
const scriptSrc = parsed.get('script-src');
expect(scriptSrc).to.be.an(Array);
expect(scriptSrc).not.to.contain('unsafe-inline');
const nonceIndex = scriptSrc.findIndex(value => value.startsWith(`'nonce-`));
expect(nonceIndex).greaterThan(-1);
scriptSrc.splice(nonceIndex, 1);

const entries = Array.from(parsed.entries());
expect(entries).to.eql([
[ 'script-src', [ '\'unsafe-eval\'' ] ],
[ 'worker-src', [ 'blob:' ] ],
[ 'child-src', [ 'blob:' ] ],
[ 'style-src', [ '\'unsafe-inline\'', '\'self\'' ] ]
]);
});
});
}