-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move CSP options to new platform (#52698)
* Move CSP options to new platform * Expose SharedGlobalConfig from root * Derive CSP options from config * Consolidate CSP configuration with HTTP config * Fix outstanding config renames * Remove legacy CSP configuration calls, migrate to platform properties * Revise docs * Fix test from type change * Expose ICspConfig, consolidate and simplify CSP defaults access * Rebase and update docs * Remove legacy API from route definition params, review nits * Clean up config path usages for consistency * Regenerate docs
- Loading branch information
1 parent
1ea9d79
commit 614bde9
Showing
52 changed files
with
601 additions
and
246 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
docs/development/core/server/kibana-plugin-server.cspconfig.default.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [CspConfig](./kibana-plugin-server.cspconfig.md) > [DEFAULT](./kibana-plugin-server.cspconfig.default.md) | ||
|
||
## CspConfig.DEFAULT property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
static readonly DEFAULT: CspConfig; | ||
``` |
11 changes: 11 additions & 0 deletions
11
docs/development/core/server/kibana-plugin-server.cspconfig.header.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [CspConfig](./kibana-plugin-server.cspconfig.md) > [header](./kibana-plugin-server.cspconfig.header.md) | ||
|
||
## CspConfig.header property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly header: string; | ||
``` |
28 changes: 28 additions & 0 deletions
28
docs/development/core/server/kibana-plugin-server.cspconfig.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [CspConfig](./kibana-plugin-server.cspconfig.md) | ||
|
||
## CspConfig class | ||
|
||
CSP configuration for use in Kibana. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare class CspConfig implements ICspConfig | ||
``` | ||
## Properties | ||
| Property | Modifiers | Type | Description | | ||
| --- | --- | --- | --- | | ||
| [DEFAULT](./kibana-plugin-server.cspconfig.default.md) | <code>static</code> | <code>CspConfig</code> | | | ||
| [header](./kibana-plugin-server.cspconfig.header.md) | | <code>string</code> | | | ||
| [rules](./kibana-plugin-server.cspconfig.rules.md) | | <code>string[]</code> | | | ||
| [strict](./kibana-plugin-server.cspconfig.strict.md) | | <code>boolean</code> | | | ||
| [warnLegacyBrowsers](./kibana-plugin-server.cspconfig.warnlegacybrowsers.md) | | <code>boolean</code> | | | ||
## Remarks | ||
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `CspConfig` class. | ||
11 changes: 11 additions & 0 deletions
11
docs/development/core/server/kibana-plugin-server.cspconfig.rules.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [CspConfig](./kibana-plugin-server.cspconfig.md) > [rules](./kibana-plugin-server.cspconfig.rules.md) | ||
|
||
## CspConfig.rules property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly rules: string[]; | ||
``` |
11 changes: 11 additions & 0 deletions
11
docs/development/core/server/kibana-plugin-server.cspconfig.strict.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [CspConfig](./kibana-plugin-server.cspconfig.md) > [strict](./kibana-plugin-server.cspconfig.strict.md) | ||
|
||
## CspConfig.strict property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly strict: boolean; | ||
``` |
11 changes: 11 additions & 0 deletions
11
docs/development/core/server/kibana-plugin-server.cspconfig.warnlegacybrowsers.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [CspConfig](./kibana-plugin-server.cspconfig.md) > [warnLegacyBrowsers](./kibana-plugin-server.cspconfig.warnlegacybrowsers.md) | ||
|
||
## CspConfig.warnLegacyBrowsers property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly warnLegacyBrowsers: boolean; | ||
``` |
13 changes: 13 additions & 0 deletions
13
docs/development/core/server/kibana-plugin-server.httpservicesetup.csp.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) > [csp](./kibana-plugin-server.httpservicesetup.csp.md) | ||
|
||
## HttpServiceSetup.csp property | ||
|
||
The CSP config used for Kibana. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
csp: ICspConfig; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
docs/development/core/server/kibana-plugin-server.icspconfig.header.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [ICspConfig](./kibana-plugin-server.icspconfig.md) > [header](./kibana-plugin-server.icspconfig.header.md) | ||
|
||
## ICspConfig.header property | ||
|
||
The CSP rules in a formatted directives string for use in a `Content-Security-Policy` header. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly header: string; | ||
``` |
23 changes: 23 additions & 0 deletions
23
docs/development/core/server/kibana-plugin-server.icspconfig.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [ICspConfig](./kibana-plugin-server.icspconfig.md) | ||
|
||
## ICspConfig interface | ||
|
||
CSP configuration for use in Kibana. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface ICspConfig | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Type | Description | | ||
| --- | --- | --- | | ||
| [header](./kibana-plugin-server.icspconfig.header.md) | <code>string</code> | The CSP rules in a formatted directives string for use in a <code>Content-Security-Policy</code> header. | | ||
| [rules](./kibana-plugin-server.icspconfig.rules.md) | <code>string[]</code> | The CSP rules used for Kibana. | | ||
| [strict](./kibana-plugin-server.icspconfig.strict.md) | <code>boolean</code> | Specify whether browsers that do not support CSP should be able to use Kibana. Use <code>true</code> to block and <code>false</code> to allow. | | ||
| [warnLegacyBrowsers](./kibana-plugin-server.icspconfig.warnlegacybrowsers.md) | <code>boolean</code> | Specify whether users with legacy browsers should be warned about their lack of Kibana security compliance. | | ||
|
13 changes: 13 additions & 0 deletions
13
docs/development/core/server/kibana-plugin-server.icspconfig.rules.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [ICspConfig](./kibana-plugin-server.icspconfig.md) > [rules](./kibana-plugin-server.icspconfig.rules.md) | ||
|
||
## ICspConfig.rules property | ||
|
||
The CSP rules used for Kibana. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly rules: string[]; | ||
``` |
13 changes: 13 additions & 0 deletions
13
docs/development/core/server/kibana-plugin-server.icspconfig.strict.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [ICspConfig](./kibana-plugin-server.icspconfig.md) > [strict](./kibana-plugin-server.icspconfig.strict.md) | ||
|
||
## ICspConfig.strict property | ||
|
||
Specify whether browsers that do not support CSP should be able to use Kibana. Use `true` to block and `false` to allow. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly strict: boolean; | ||
``` |
13 changes: 13 additions & 0 deletions
13
docs/development/core/server/kibana-plugin-server.icspconfig.warnlegacybrowsers.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [ICspConfig](./kibana-plugin-server.icspconfig.md) > [warnLegacyBrowsers](./kibana-plugin-server.icspconfig.warnlegacybrowsers.md) | ||
|
||
## ICspConfig.warnLegacyBrowsers property | ||
|
||
Specify whether users with legacy browsers should be warned about their lack of Kibana security compliance. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly warnLegacyBrowsers: boolean; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { TypeOf, schema } from '@kbn/config-schema'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export type CspConfigType = TypeOf<typeof config.schema>; | ||
|
||
export const config = { | ||
// TODO: Move this to server.csp using config deprecations | ||
// ? https://github.com/elastic/kibana/pull/52251 | ||
path: 'csp', | ||
schema: schema.object({ | ||
rules: schema.arrayOf(schema.string(), { | ||
defaultValue: [ | ||
`script-src 'unsafe-eval' 'self'`, | ||
`worker-src blob: 'self'`, | ||
`style-src 'unsafe-inline' 'self'`, | ||
], | ||
}), | ||
strict: schema.boolean({ defaultValue: true }), | ||
warnLegacyBrowsers: schema.boolean({ defaultValue: true }), | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { CspConfig } from '.'; | ||
|
||
// CSP rules aren't strictly additive, so any change can potentially expand or | ||
// restrict the policy in a way we consider a breaking change. For that reason, | ||
// we test the default rules exactly so any change to those rules gets flagged | ||
// for manual review. In other words, this test is intentionally fragile to draw | ||
// extra attention if defaults are modified in any way. | ||
// | ||
// A test failure here does not necessarily mean this change cannot be made, | ||
// but any change here should undergo sufficient scrutiny by the Kibana | ||
// security team. | ||
// | ||
// The tests use inline snapshots to make it as easy as possible to identify | ||
// the nature of a change in defaults during a PR review. | ||
|
||
describe('CspConfig', () => { | ||
test('DEFAULT', () => { | ||
expect(CspConfig.DEFAULT).toMatchInlineSnapshot(` | ||
CspConfig { | ||
"header": "script-src 'unsafe-eval' 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'", | ||
"rules": Array [ | ||
"script-src 'unsafe-eval' 'self'", | ||
"worker-src blob: 'self'", | ||
"style-src 'unsafe-inline' 'self'", | ||
], | ||
"strict": true, | ||
"warnLegacyBrowsers": true, | ||
} | ||
`); | ||
}); | ||
|
||
test('defaults from config', () => { | ||
expect(new CspConfig()).toMatchInlineSnapshot(` | ||
CspConfig { | ||
"header": "script-src 'unsafe-eval' 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'", | ||
"rules": Array [ | ||
"script-src 'unsafe-eval' 'self'", | ||
"worker-src blob: 'self'", | ||
"style-src 'unsafe-inline' 'self'", | ||
], | ||
"strict": true, | ||
"warnLegacyBrowsers": true, | ||
} | ||
`); | ||
}); | ||
|
||
test('creates from partial config', () => { | ||
expect(new CspConfig({ strict: false, warnLegacyBrowsers: false })).toMatchInlineSnapshot(` | ||
CspConfig { | ||
"header": "script-src 'unsafe-eval' 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'", | ||
"rules": Array [ | ||
"script-src 'unsafe-eval' 'self'", | ||
"worker-src blob: 'self'", | ||
"style-src 'unsafe-inline' 'self'", | ||
], | ||
"strict": false, | ||
"warnLegacyBrowsers": false, | ||
} | ||
`); | ||
}); | ||
|
||
test('computes header from rules', () => { | ||
const cspConfig = new CspConfig({ rules: ['alpha', 'beta', 'gamma'] }); | ||
|
||
expect(cspConfig).toMatchInlineSnapshot(` | ||
CspConfig { | ||
"header": "alpha; beta; gamma", | ||
"rules": Array [ | ||
"alpha", | ||
"beta", | ||
"gamma", | ||
], | ||
"strict": true, | ||
"warnLegacyBrowsers": true, | ||
} | ||
`); | ||
}); | ||
}); |
Oops, something went wrong.