forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional prototype pollution protections (elastic#206073)
## Summary 1. Extends the server-side prototype pollution protections introduced in elastic#190716 to include `Array.prototype`. 2. Applies the same prototype pollution protections to the client-side. ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] Sealing prototypes on the client can lead to failures in third-party dependencies. I'm relying on sufficient functional test coverage to detect issues here. As a result, these protections are disabled by default for now, and can be controlled via setting `server.prototypeHardening: true/false` --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
dcf64f2
commit 9ce2dd8
Showing
40 changed files
with
360 additions
and
86 deletions.
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
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
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
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
1 change: 1 addition & 0 deletions
1
src/core/packages/http/server-internal/src/__snapshots__/http_config.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
2 changes: 2 additions & 0 deletions
2
...ckages/rendering/server-internal/src/bootstrap/__snapshots__/render_template.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
32 changes: 32 additions & 0 deletions
32
src/platform/packages/shared/kbn-security-hardening/BUILD.bazel
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,32 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", "js_library") | ||
|
||
SRCS = glob( | ||
[ | ||
"**/*.ts", | ||
], | ||
exclude = [ | ||
"**/test_helpers.ts", | ||
"**/*.config.js", | ||
"**/*.mock.*", | ||
"**/*.test.*", | ||
"**/*.stories.*", | ||
"**/__snapshots__/**", | ||
"**/integration_tests/**", | ||
"**/mocks/**", | ||
"**/scripts/**", | ||
"**/storybook/**", | ||
"**/test_fixtures/**", | ||
"**/test_helpers/**", | ||
], | ||
) | ||
|
||
BUNDLER_DEPS = [ | ||
] | ||
|
||
js_library( | ||
name = "kbn-security-hardening", | ||
package_name = "@kbn/security-hardening", | ||
srcs = ["package.json"] + SRCS, | ||
deps = BUNDLER_DEPS, | ||
visibility = ["//visibility:public"], | ||
) |
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
44 changes: 44 additions & 0 deletions
44
src/platform/packages/shared/kbn-security-hardening/prototype.ts
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,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
/** | ||
* Harden the prototypes of built-in objects to prevent prototype pollution attacks. | ||
* This function should be called after the polyfills have been loaded, as some polyfills require the prototypes to be mutable. | ||
* The one known requirement is corejs mutating the Array prototype. | ||
*/ | ||
function hardenPrototypesPostPolyfill() { | ||
// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal | ||
// > The Object.seal() static method seals an object. | ||
// > Sealing an object prevents extensions and makes existing properties non-configurable. | ||
// > A sealed object has a fixed set of properties: new properties cannot be added, existing properties cannot be removed, | ||
// > their enumerability and configurability cannot be changed, and its prototype cannot be re-assigned. | ||
// > Values of existing properties can still be changed as long as they are writable. | ||
// Object.freeze would take this one step further, and prevent the values of the properties from being changed as well. | ||
// This is not currently feasible for Kibana, as this functionality is required for some of the libraries that we use, such as react-dom/server. | ||
// While Object.seal() is not a silver bullet, it does provide a good balance between security and compatibility. | ||
// The goal is to prevent a majority of prototype pollution vulnerabilities that can be exploited by an attacker. | ||
|
||
// ** IMPORTANT ** | ||
// This is used both in the browser and in Node.js. | ||
// For Node.js, we _additionally_ seal most prototypes in `src/setup_node_env/harden/prototype.js`. | ||
// This results in sealing most prototypes twice on the server, with the exception of `Array.prototype`, which is only sealed here. | ||
// The extra seal is a no-op, but it is done to ensure that the same code is run in both environments. | ||
|
||
Object.seal(Object.prototype); | ||
Object.seal(Number.prototype); | ||
Object.seal(String.prototype); | ||
Object.seal(Function.prototype); | ||
Object.seal(Array.prototype); | ||
} | ||
|
||
// Use of the `KBN_UNSAFE_DISABLE_PROTOTYPE_HARDENING` environment variable is discouraged, and should only be set to facilitate testing | ||
// specific scenarios. This should never be set in production. | ||
if (!process.env.KBN_UNSAFE_DISABLE_PROTOTYPE_HARDENING) { | ||
hardenPrototypesPostPolyfill(); | ||
} |
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
Oops, something went wrong.