mirror of
https://github.com/github/codeql.git
synced 2026-04-20 06:24:03 +02:00
Document and test YAML.safe_load
This commit is contained in:
@@ -27,8 +27,9 @@ are capable of deserializing to arbitrary objects, this is inherently unsafe.
|
||||
</p>
|
||||
<sample src="examples/UnsafeDeserializationBad.rb"/>
|
||||
<p>
|
||||
Using <code>YAML.parse</code> instead, with the default options, removes the
|
||||
vulnerability.
|
||||
Using <code>JSON.parse</code> and <code>YAML.safe_load</code> instead, as in the
|
||||
following example, removes the vulnerability. Note that there is no safe way to
|
||||
deserialize untrusted data using <code>Marshal</code>.
|
||||
</p>
|
||||
<sample src="examples/UnsafeDeserializationGood.rb"/>
|
||||
</example>
|
||||
|
||||
@@ -5,4 +5,9 @@ class UserController < ActionController::Base
|
||||
object = JSON.parse params[:json]
|
||||
# ...
|
||||
end
|
||||
|
||||
def safe_yaml_example
|
||||
object = YAML.safe_load params[:yaml]
|
||||
# ...
|
||||
end
|
||||
end
|
||||
@@ -38,4 +38,10 @@ class UsersController < ActionController::Base
|
||||
yaml_data = params[:key]
|
||||
object = YAML.load yaml_data
|
||||
end
|
||||
|
||||
# GOOD
|
||||
def route6
|
||||
yaml_data = params[:key]
|
||||
object = YAML.safe_load yaml_data
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user