You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can you please be more specific about the desired behavior? Is it acceptable to load Symbols? Are subclasses of Ruby primitives considered "primitive"? If someone sets an instance variable on a string, then dumps / loads that string, should the instance variable survive?
Can you please demonstrate how to use YAML dump / load to execute arbitrary code? AFAIK it depends on objects other than YAML.
Symbols, sure they are primitives. In order to prevent a DoS via Symbols, perhaps there should be a configuration mechanism to specify exactly what types/tags should be allowed.
Subclasses of primitives are no longer primitives. In safe mode the custom class could be ignored and the primitive class used instead.
Instance variables in primitives should not survive.
Can you please demonstrate how to use YAML dump / load to execute arbitrary code?
Which is why I believe there should be a safe_load method or a configuration mechanism that restricts YAML to only loading primitives or explicitly allowed Classes.
Symbols, sure they are primitives. In order to prevent a DoS via Symbols, perhaps there should be a configuration > mechanism to specify exactly what types/tags should be allowed.
Subclasses of primitives are no longer primitives. In safe mode the custom class could be ignored and the primitive > class used instead.
Instance variables in primitives should not survive.
👍 on what @postmodern and @charliesome are saying. I really wish it supported a way for it to skip over everything and raise what isn't in the specs by default, and certainly like what @charliesome said about skipping over symbols too... the symbols part is kind of important to me because it would make it easier to keep a consistent configuration file to API without having to run to_s on all the keys myself before I create an indifferent Hash.
Instead of having a big case/when statement of all the tags in to_ruby.rb, Psych could have a table of parser methods/procs. This way Psych could be configured to run in "safe mode". When an unknown tag is encountered, it could skip over it (and it's children) or raise an exception.
@tenderlove YAML just happened to call #[]= on an instance of the Class we specified. ActionController::Routing::RouteSet::NamedRouteCollection just so happens to pass the key value from #[]= down to module_eval. We could have used other non-Rails Classes that somehow pass our data into instance_eval or send. CVE-2013-0156 is not really specific to Rails, other applications that accept arbitrary YAML are also vulnerable; such as chef-server which uses extlib.
@tenderlove YAML just happened to call #[]= on an instance of the Class we specified. ActionController::Routing::RouteSet::NamedRouteCollection just so happens to pass the key value from #[]= down to module_eval. We could have used other non-Rails Classes that somehow pass our data into instance_eval or send. CVE-2013-0156 is not really specific to Rails, other applications that accept arbitrary YAML are also vulnerable; such as chef-server which uses extlib.
Please refer to the Rails PoC write up for a full walk through.
�
Reply to this email directly or view it on GitHub.
Marshal.load has this problem as well and so would any serialization mechanism that does the following with arbitrary Foo classes and arbitrary field values.
We are discussing convenience vs security and I cannot believe you are in favour of convenience at such a risk.
I'm affraid, my experience in the ruby world seems to suggest that ruby programmers tend to favor convenience over almost everything, including security. Given what you've already told about your project and concerns, I'm not sure the ruby/rails culture will fit very well.
YAML
serialization language
serialization
broadly useful for programming needs
broadly useful
broadly
configuration files to Internet messaging
configuration files
Just because it says it can be used for the internet doesn't mean it's a good idea and doesn't mean "should".
@Kimcha changing YAML.load would not just break the application, it would break many dependencies. The change would be comparable to upgrading from 1.8 to 1.9.
We are discussing convenience vs security and I cannot believe you are in favour of convenience at such a risk.
I do not agree that this is a binary choice between convenience and security, that we must be forced into choosing one or the other. It is simply the matter of the right tool for the right job:
Is the YAML input trusted: YAML.load
Is the YAML input from the user: YAML.load_safe
Just because nobody has reported to the rails security team that a part is vulnerable, doesnt mean it is not.
This is where one should take extreme measures, such as auditing their code-base for any YAML.load calls. On a more philosophical note, we can never know every vulnerability before they are reported. We can only respond to vulnerabilities as they are reported.
It is an never ending game to try to fix all the attacking vectors when you can simply fix it at the root of the issue in default behaviour.
You assume that every developer (and user) would immediately upgrade to the latest version of Psych containing safe_load. :) Although, there is a bit of truth to this. Even if we were to audit every rubygem and every Rails app, a clueless (or sleep deprived) developer could still use YAML.load unsafely. The Ruby programming language does not prevent the developer from making bad design decisions. Even if we changed YAML.load to behave like YAML.safe_load, there is still eval, instance_eval, module_eval, send, system, CSV.load, JSON.load. Likewise, SQL injection and XSS are still possible in the Java and Haskell programming languages. A competent developer must be aware of the potential dangers of their languages/frameworks and avoid them. I feel that Secure Coding Guidelines are a part of the solution here.
@Kimcha something I haven't told you about the ruby world: confusion. A nice example from @postmodern here:
It is simply the matter of the right tool for the right job:
Is the YAML input trusted: YAML.load
Is the YAML input from the user: YAML.load_safe
Very strong confusion between functional requirements (loading data that might or might not contain only scalars) and non-functional requirements (keeping the operation safe).
There is no such right tool for the right job, especially when your job tells you to load non-scalar data in a safe way. Anyway...
continuing #119 (comment) - I assume that every developer does not write to_s_safe, you just assume that default is the safe the same default in the feature should be safe, even if it takes 3 years to make it happen - we should make it happen.
Would it be hard to announce an deprecation today, add a warning in a year, allow flag in two years and switch the new default in 3 years - is it enough time to make things safe?
I think YAML.load should remain as it is, .load implies that we are trusting the input, just as in Marshal.load or CSV.load. Perhaps, by analogy, the primitives-only version should be YAML.parse?
Activity
tenderlove commentedon Jan 13, 2013
Can you please be more specific about the desired behavior? Is it acceptable to load Symbols? Are subclasses of Ruby primitives considered "primitive"? If someone sets an instance variable on a string, then dumps / loads that string, should the instance variable survive?
Can you please demonstrate how to use YAML dump / load to execute arbitrary code? AFAIK it depends on objects other than YAML.
postmodern commentedon Jan 14, 2013
rails_rce.rb
Which is why I believe there should be a
safe_loadmethod or a configuration mechanism that restricts YAML to only loading primitives or explicitly allowed Classes.tenderlove commentedon Jan 14, 2013
@postmodern does the
rails_rce.rbscript depend on code other than YAML? I'm confused.tenderlove commentedon Jan 14, 2013
Given these points, why not just use JSON?
postmodern commentedon Jan 14, 2013
JSON does not support Symbols, does not support non-String-keyed Hashes and does not have special formatting such as:
Is there any reason YAML should not have a secure mode?
postmodern commentedon Jan 14, 2013
@tenderlove
rails_rce.rbuses!ruby/hash:MyClassandActionController::Routing::RouteSet::NamedRouteCollection.@charliesome's PoC used
ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy,ERB,Gem::RequirementandRack::Session::Cookie::Base64::Marshal.These exploits would not work if the YAML parser was configured to only allow primitives (aka
safe_load).haileys commentedon Jan 14, 2013
+1. Only primitives that YAML can deserialize without using
!directives should be allowed.No symbols IMO. I can't see a use case where you would want to allow symbols but still restrict other deserialization.
envygeeks commentedon Jan 14, 2013
👍 on what @postmodern and @charliesome are saying. I really wish it supported a way for it to skip over everything and raise what isn't in the specs by default, and certainly like what @charliesome said about skipping over symbols too... the symbols part is kind of important to me because it would make it easier to keep a consistent configuration file to API without having to run to_s on all the keys myself before I create an indifferent Hash.
postmodern commentedon Jan 14, 2013
Instead of having a big
case/whenstatement of all the tags in to_ruby.rb, Psych could have a table of parser methods/procs. This way Psych could be configured to run in "safe mode". When an unknown tag is encountered, it could skip over it (and it's children) or raise an exception.envygeeks commentedon Jan 14, 2013
There is no other option other than
raisean exception so it 💣 and somebody knows they did bad.tenderlove commentedon Jan 14, 2013
@postmodern so YAML didn't execute the code, but Rails did?
I don't particularly care whether it does or not. We just have to be specific about what it means. Also, we need someone to write the patch. :-)
postmodern commentedon Jan 14, 2013
@tenderlove YAML just happened to call
#[]=on an instance of the Class we specified.ActionController::Routing::RouteSet::NamedRouteCollectionjust so happens to pass the key value from#[]=down tomodule_eval. We could have used other non-Rails Classes that somehow pass our data intoinstance_evalorsend. CVE-2013-0156 is not really specific to Rails, other applications that accept arbitrary YAML are also vulnerable; such as chef-server which uses extlib.Please see the Rails PoC write up for a full walk through.
tenderlove commentedon Jan 14, 2013
Ah, so it's not specific to YAML, but anything that will feed strings to eval. Makes sense.
Aaron Patterson
http://tenderlovemaking.com/
I'm on an iPhone so I apologize for top posting.
On Jan 13, 2013, at 7:26 PM, Postmodern notifications@github.com wrote:
benmmurphy commentedon Jan 14, 2013
Marshal.load has this problem as well and so would any serialization mechanism that does the following with arbitrary Foo classes and arbitrary field values.
envygeeks commentedon Jan 14, 2013
@benmmurphy it's in
Marshal's nature to be like this by simple definition of what it is, YAML however, it's not.103 remaining items
blambeau commentedon Feb 12, 2013
@Kimcha
I'm affraid, my experience in the ruby world seems to suggest that ruby programmers tend to favor convenience over almost everything, including security. Given what you've already told about your project and concerns, I'm not sure the ruby/rails culture will fit very well.
envygeeks commentedon Feb 12, 2013
@blambeau I'll just leave this here:
Just because it says it can be used for the internet doesn't mean it's a good idea and doesn't mean "should".
postmodern commentedon Feb 12, 2013
@Kimcha changing
YAML.loadwould not just break the application, it would break many dependencies. The change would be comparable to upgrading from 1.8 to 1.9.I do not agree that this is a binary choice between convenience and security, that we must be forced into choosing one or the other. It is simply the matter of the right tool for the right job:
YAML.loadYAML.load_safeThis is where one should take extreme measures, such as auditing their code-base for any
YAML.loadcalls. On a more philosophical note, we can never know every vulnerability before they are reported. We can only respond to vulnerabilities as they are reported.You assume that every developer (and user) would immediately upgrade to the latest version of Psych containing
safe_load. :) Although, there is a bit of truth to this. Even if we were to audit every rubygem and every Rails app, a clueless (or sleep deprived) developer could still useYAML.loadunsafely. The Ruby programming language does not prevent the developer from making bad design decisions. Even if we changedYAML.loadto behave likeYAML.safe_load, there is stilleval,instance_eval,module_eval,send,system,CSV.load,JSON.load. Likewise, SQL injection and XSS are still possible in the Java and Haskell programming languages. A competent developer must be aware of the potential dangers of their languages/frameworks and avoid them. I feel that Secure Coding Guidelines are a part of the solution here.blambeau commentedon Feb 12, 2013
@Kimcha something I haven't told you about the ruby world: confusion. A nice example from @postmodern here:
Very strong confusion between functional requirements (loading data that might or might not contain only scalars) and non-functional requirements (keeping the operation safe).
There is no such
right tool for the right job, especially when your job tells you to load non-scalar data in a safe way. Anyway...mpapis commentedon Feb 16, 2013
continuing #119 (comment) - I assume that every developer does not write
to_s_safe, you just assume that default is thesafethe same default in the feature should besafe, even if it takes 3 years to make it happen - we should make it happen.Would it be hard to announce an deprecation today, add a warning in a year, allow flag in two years and switch the
newdefault in 3 years - is it enough time to make thingssafe?crazymykl commentedon Feb 20, 2013
I think YAML.load should remain as it is, .load implies that we are trusting the input, just as in Marshal.load or CSV.load. Perhaps, by analogy, the primitives-only version should be YAML.parse?
envygeeks commentedon Feb 20, 2013
If you want to fall inline with JSON then sure, which I wouldn't mind since it means consistency.
trevor commentedon Jun 2, 2013
since it hasn't been mentioned, here's documentation that contains examples of python's / pyyaml's take on safe_load: http://pyyaml.org/wiki/PyYAMLDocumentation
tenderlove commentedon Jul 5, 2013
safe_loadis added and released in 2.0.0, so I'm closing this.envygeeks commentedon Jul 5, 2013
Thank you!
postmodern commentedon Jul 5, 2013
w00t finally!
Document the fact that ParseYaml middleware is unsafe
Document the fact that ParseYaml middleware is unsafe
Parse YAML safely