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

Harden creation of child processes #55697

Merged
merged 17 commits into from
Mar 10, 2020
Merged

Conversation

watson
Copy link
Contributor

@watson watson commented Jan 23, 2020

Add general protection against RCE vulnerabilities similar to the one described in CVE-2019-7609.

Unfortunately, our normal testing framework Jest, changes the behavior of process.env in a way so that we can't test that our patches works as expected. We, therefore, have to introduce another testing framework in this PR that we can use to test our hardening functionality. I've chosen tape because it's very simple, is widely used in the Node.js community, and doesn't add any magic to the environment.

Closes #49605

@watson watson added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.7.0 labels Jan 23, 2020
@watson watson requested a review from a team as a code owner January 23, 2020 13:43
@watson watson self-assigned this Jan 23, 2020
@watson watson added the Feature:Hardening Harding of Kibana from a security perspective label Jan 23, 2020
@watson watson requested a review from a team January 23, 2020 13:47
@watson
Copy link
Contributor Author

watson commented Jan 23, 2020

@elasticmachine merge upstream

@watson
Copy link
Contributor Author

watson commented Jan 27, 2020

@elasticmachine merge upstream

@jportner jportner self-requested a review January 27, 2020 14:48
Copy link
Contributor

@jportner jportner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still want to play around with this, but some initial feedback:

  1. This hardening is pretty important, can we add some unit tests to verify it's working as intended? This will also help with maintainability for others who may not be well-versed in this topic.
  2. What do you think about updating the Codeowners file to tag the Security team as a joint co-owner of the src/setup_node_env directory?

src/setup_node_env/index.js Outdated Show resolved Hide resolved
@jportner
Copy link
Contributor

Okay, I tested this out and it looks great so far!

Two more questions:

  1. Does it also make sense to harden subprocess.send?
  2. I tested this out by creating a file named "scripts/test.ts", and it doesn't appear that the process.env hardening works. I'm not sure what I'm doing wrong, can you take a look below?
require('../src/setup_node_env');

const { create, ObjectPrototype } = require('object-prototype');

const obj1 = process.env;
const obj2 = {};

console.log(Object.prototype.isPrototypeOf(obj1)); // expected: false, actual: true
console.log(ObjectPrototype.isPrototypeOf(obj1)); // expected: true, actual: false

console.log(Object.prototype.isPrototypeOf(obj2)); // expected: true, actual: true
console.log(ObjectPrototype.isPrototypeOf(obj2)); // expected: false, actual: false

Object.prototype.foo = 42;

console.log(obj1.foo); // expected: undefined, actual: 42
console.log(obj2.foo); // expected: 42, actual: 42

@watson
Copy link
Contributor Author

watson commented Jan 29, 2020

@jportner Good catch! I found the bug and pushed a fix. This just shows the importance of tests, so as you suggested, I'll add some and push again.

@watson
Copy link
Contributor Author

watson commented Jan 29, 2020

@elasticmachine merge upstream

@kobelb
Copy link
Contributor

kobelb commented Jan 29, 2020

ACK: reviewing!

Copy link
Contributor

@kobelb kobelb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not overly fond of us splitting up this logic into two external node packages: object-prototype and object-prototype-functions.

In general, we've refrained from creating external repos and packages until there was a reason to do so. And when that time came, they've generally resided under the elastic organization. While I do see the merit in allowing others to benefit from the same approach that Kibana is taking to harden itself, it feels like we're doing so prematurely. I'd prefer we move this code to be within the Kibana repo until it's more mature and we deem it beneficial to make a separate package.

yarn.lock Outdated Show resolved Hide resolved
yarn.lock Outdated Show resolved Hide resolved
yarn.lock Outdated Show resolved Hide resolved
src/setup_node_env/patches/child_process.js Show resolved Hide resolved
src/setup_node_env/harden.js Outdated Show resolved Hide resolved
src/setup_node_env/patches/child_process.js Show resolved Hide resolved
@watson
Copy link
Contributor Author

watson commented Jan 31, 2020

@elasticmachine merge upstream

1 similar comment
@watson
Copy link
Contributor Author

watson commented Feb 3, 2020

@elasticmachine merge upstream

@watson
Copy link
Contributor Author

watson commented Feb 3, 2020

@kobelb
Copy link
Contributor

kobelb commented Feb 4, 2020

ACK: will re-review first thing tomorrow

package.json Outdated Show resolved Hide resolved
yarn.lock Outdated Show resolved Hide resolved
test/harden/process_env.js Outdated Show resolved Hide resolved
scripts/test_hardening.js Outdated Show resolved Hide resolved
test/harden/child_process.js Show resolved Hide resolved
src/setup_node_env/patches/child_process.js Show resolved Hide resolved
src/setup_node_env/patches/child_process.js Outdated Show resolved Hide resolved
src/setup_node_env/patches/child_process.js Outdated Show resolved Hide resolved
Co-Authored-By: Larry Gregory <lgregorydev@gmail.com>
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

package.json Show resolved Hide resolved
Copy link
Member

@mistic mistic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested that PR with #47998 and it did not affect it at all.
It LGTM

@watson watson merged commit a663f65 into elastic:master Mar 10, 2020
@watson watson deleted the harden-child-processes branch March 10, 2020 06:52
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 10, 2020
* master: (22 commits)
  Generate docs from data plugin (elastic#56955)
  Fixes elastic#59513 by hiding one of the symmetric edges rather than omiting it (elastic#59514)
  Harden creation of child processes (elastic#55697)
  [Alerting] replace watcher http APIs used by index threshold Alerting (elastic#59475)
  [Maps][docs] add more details to Quantitative data driven styling docs (elastic#59553)
  chore: 🤖 hide Drilldowns in master (elastic#59698)
  [Discover] Migrate AppState/GlobalState to new app state helpers (elastic#57175)
  Use HTTP request schemas to create types, use those types in the client (elastic#59340)
  [Maps] Support categorical styling for numbers and dates (elastic#57908)
  [ML] Functional API tests - bucket span estimation with custom search.max_buckets (elastic#59665)
  Fix slm_ui setting by changing camel case back to snake case. (elastic#59663)
  removes beta tag (elastic#59618)
  [DOCS] Removed spatial references (elastic#59595)
  fix outdated docs (elastic#58729)
  [ML] Fixes bucket span estimators loading of max_buckets setting (elastic#59639)
  [ML] Refactoring anomaly detector job types (elastic#59556)
  [Upgrade Assistant] Better handling of closed indices (elastic#58890)
  additional visualizations plugin cleanup before moving to NP (elastic#59318)
  In scripted fields, unable to switch the `Type` - getting a console error which says - Class constructor DecoratedFieldFormat cannot be invoked without 'new' (elastic#59285)
  [Visualize] Remove global state in visualize (elastic#58352)
  ...
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 10, 2020
…s/kibana into alerting/fix-flaky-instance-test

* 'alerting/fix-flaky-instance-test' of github.com:gmmorris/kibana: (176 commits)
  Generate docs from data plugin (elastic#56955)
  Fixes elastic#59513 by hiding one of the symmetric edges rather than omiting it (elastic#59514)
  Harden creation of child processes (elastic#55697)
  [Alerting] replace watcher http APIs used by index threshold Alerting (elastic#59475)
  [Maps][docs] add more details to Quantitative data driven styling docs (elastic#59553)
  chore: 🤖 hide Drilldowns in master (elastic#59698)
  [Discover] Migrate AppState/GlobalState to new app state helpers (elastic#57175)
  Use HTTP request schemas to create types, use those types in the client (elastic#59340)
  [Maps] Support categorical styling for numbers and dates (elastic#57908)
  [ML] Functional API tests - bucket span estimation with custom search.max_buckets (elastic#59665)
  Fix slm_ui setting by changing camel case back to snake case. (elastic#59663)
  removes beta tag (elastic#59618)
  [DOCS] Removed spatial references (elastic#59595)
  fix outdated docs (elastic#58729)
  [ML] Fixes bucket span estimators loading of max_buckets setting (elastic#59639)
  [ML] Refactoring anomaly detector job types (elastic#59556)
  [Upgrade Assistant] Better handling of closed indices (elastic#58890)
  additional visualizations plugin cleanup before moving to NP (elastic#59318)
  In scripted fields, unable to switch the `Type` - getting a console error which says - Class constructor DecoratedFieldFormat cannot be invoked without 'new' (elastic#59285)
  [Visualize] Remove global state in visualize (elastic#58352)
  ...
watson added a commit that referenced this pull request Mar 10, 2020
Add general protection against RCE vulnerabilities similar to the one
described in CVE-2019-7609.

Closes #49605
jkelastic pushed a commit to jkelastic/kibana that referenced this pull request Mar 12, 2020
Add general protection against RCE vulnerabilities similar to the one
described in CVE-2019-7609.

Closes elastic#49605
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Hardening Harding of Kibana from a security perspective release_note:skip Skip the PR/issue when compiling release notes v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure spawning of child processes are not susceptible to prototype pollution
6 participants