-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Move CSP options to new platform #52698
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ce94394
Move CSP options to new platform
eliperelman 51f2fb1
Expose SharedGlobalConfig from root
eliperelman 6b1f50f
Derive CSP options from config
eliperelman 6d46ff3
Consolidate CSP configuration with HTTP config
eliperelman 0725c62
Fix outstanding config renames
eliperelman 9601749
Remove legacy CSP configuration calls, migrate to platform properties
eliperelman eb224e6
Revise docs
eliperelman f6339cb
Fix test from type change
eliperelman fd90dfe
Expose ICspConfig, consolidate and simplify CSP defaults access
eliperelman b81a6f8
Rebase and update docs
eliperelman b3ebf53
Remove legacy API from route definition params, review nits
eliperelman 451da17
Clean up config path usages for consistency
eliperelman fd01be7
Regenerate docs
eliperelman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 }), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll have to be careful when backporting this, as the default in 7.x is
kobelb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding renaming the
csp
config key, I will handle this in another PR and make sure we reach consensus between the Platform and Security teams =)