Skip to content

Commit

Permalink
configurable CSP owned by security team
Browse files Browse the repository at this point in the history
  • Loading branch information
epixa committed Jan 31, 2019
1 parent d993433 commit 1cbf478
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# Security
/x-pack/plugins/security/ @elastic/kibana-security
/x-pack/plugins/spaces/ @elastic/kibana-security
/src/server/csp/ @elastic/kibana-security

# Design
**/*.scss @elastic/kibana-design
Expand Down
6 changes: 6 additions & 0 deletions src/server/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import {
getData
} from '../path';
import { DEFAULT_CSP_RULES, DEFAULT_CSP_LEGACY_BROWSER_RULES } from '../csp';

const tilemapSchema = Joi.object({
url: Joi.string(),
Expand Down Expand Up @@ -94,6 +95,11 @@ export default () => Joi.object({
exclusive: Joi.boolean().default(false)
}).default(),

csp: Joi.object({
rules: Joi.array().items(Joi.string()).default(DEFAULT_CSP_RULES),
legacyBrowserRules: Joi.array().items(Joi.string()).default(DEFAULT_CSP_LEGACY_BROWSER_RULES),
}).default(),

cpu: Joi.object({
cgroup: Joi.object({
path: Joi.object({
Expand Down
18 changes: 7 additions & 11 deletions src/ui/ui_render/ui_render_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
* under the License.
*/

import { createHash, randomBytes } from 'crypto';
import { promisify } from 'util';
import { createHash } from 'crypto';
import { props, reduce as reduceAsync } from 'bluebird';
import Boom from 'boom';
import { resolve } from 'path';
Expand All @@ -27,8 +26,7 @@ import { i18n } from '@kbn/i18n';
import { AppBootstrap } from './bootstrap';
import { mergeVariables } from './lib';
import { fromRoot } from '../../utils';

const randomBytesAsync = promisify(randomBytes);
import { generateCSPNonce, createCSPRuleString } from '../../server/csp';

export function uiRenderMixin(kbnServer, server, config) {
function replaceInjectedVars(request, injectedVars) {
Expand Down Expand Up @@ -215,7 +213,7 @@ export function uiRenderMixin(kbnServer, server, config) {
injectedVarsOverrides
});

const nonce = (await randomBytesAsync(12)).toString('base64');
const nonce = await generateCSPNonce();

const response = h.view('ui_app', {
nonce,
Expand Down Expand Up @@ -245,13 +243,11 @@ export function uiRenderMixin(kbnServer, server, config) {
},
});

const csp = [
`script-src 'unsafe-eval' 'nonce-${nonce}'`,
'worker-src blob:',
'child-src blob:',
];
const csp = createCSPRuleString(config.get('csp.rules'), nonce);
response.header('content-security-policy', csp);

response.header('content-security-policy', csp.join(';'));
const legacyCsp = createCSPRuleString(config.get('csp.legacyBrowserRules'), nonce);
response.header('x-content-security-policy', legacyCsp);

return response;
}
Expand Down

0 comments on commit 1cbf478

Please sign in to comment.