safe_yaml 1.0.0rc2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/README.md +25 -24
- data/bundle_install_all_ruby_versions.sh +0 -0
- data/lib/safe_yaml/transform/to_integer.rb +3 -2
- data/lib/safe_yaml/version.rb +1 -1
- data/safe_yaml.gemspec +2 -2
- data/spec/transform/to_integer_spec.rb +5 -0
- metadata +30 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bf7e5c41614da36f8ccd36e18b855f8e29c4060e
|
4
|
+
data.tar.gz: a0c48508dea39d200aea9f5fb689a6957c9ba235
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b67c8e20aea0cc1898e5af8ff8b5e8e98e4ae522b6d18a692b2649faea810b674967af561c027f160316977964fc235c99bd5fc2ee41930f610ad4d96c7bc7f5
|
7
|
+
data.tar.gz: 6c524eb43f7878a8e01c0db24680d939531313328d62a424d49cf75776bcef66854e5c5589dd9fef5dd47633c013635c24ece5e04ab5c2d8a19f2c3ea926e6ba
|
data/README.md
CHANGED
@@ -12,28 +12,29 @@ Installation
|
|
12
12
|
|
13
13
|
Add this line to your application's Gemfile:
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
$ bundle
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
|
-
$ gem install safe_yaml
|
15
|
+
```ruby
|
16
|
+
gem "safe_yaml"
|
17
|
+
```
|
24
18
|
|
25
19
|
Configuration
|
26
20
|
-------------
|
27
21
|
|
28
|
-
|
22
|
+
If *all you do* is add SafeYAML to your project, then `YAML.load` will operate in "safe" mode, which means it won't deserialize arbitrary objects. However, it will issue a warning the first time you call it because you haven't explicitly specified whether you want safe or unsafe behavior by default. To specify this behavior (e.g., in a Rails initializer):
|
29
23
|
|
30
|
-
|
31
|
-
|
24
|
+
```ruby
|
25
|
+
SafeYAML::OPTIONS[:default_mode] = :safe # or :unsafe
|
26
|
+
```
|
27
|
+
|
28
|
+
Another important option you might want to specify on startup is whether or not to allow *symbols* to be deserialized. The default setting is `false`, since symbols are not garbage collected in Ruby and so deserializing them from YAML may render your application vulnerable to a DOS (denial of service) attack. To allow symbol deserialization by default:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
SafeYAML::OPTIONS[:deserialize_symbols] = true
|
32
|
+
```
|
32
33
|
|
33
34
|
For more information on these and other options, see the "Usage" section down below.
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
What is this gem for, exactly?
|
37
|
+
------------------------------
|
37
38
|
|
38
39
|
Suppose your application were to use a popular open source library which contained code like this:
|
39
40
|
|
@@ -87,13 +88,13 @@ When you require the safe_yaml gem in your project, `YAML.load` is patched to ac
|
|
87
88
|
|
88
89
|
The most important option is the `:safe` option (default: `true`), which controls whether or not to deserialize arbitrary objects when parsing a YAML document. The other options, along with explanations, are as follows.
|
89
90
|
|
90
|
-
- `:deserialize_symbols` (default: `false`): Controls whether or not YAML will deserialize symbols. It is probably best to only enable this option where necessary, e.g. to make trusted libraries work. Symbols receive special treatment in Ruby and are not garbage collected, which means deserializing them indiscriminately may render your site vulnerable to a DOS attack
|
91
|
+
- `:deserialize_symbols` (default: `false`): Controls whether or not YAML will deserialize symbols. It is probably best to only enable this option where necessary, e.g. to make trusted libraries work. Symbols receive special treatment in Ruby and are not garbage collected, which means deserializing them indiscriminately may render your site vulnerable to a DOS attack.
|
91
92
|
|
92
93
|
- `:whitelisted_tags`: Accepts an array of YAML tags that designate trusted types, e.g., ones that can be deserialized without worrying about any resulting security vulnerabilities. When any of the given tags are encountered in a YAML document, the associated data will be parsed by the underlying YAML engine (Syck or Psych) for the version of Ruby you are using. See the "Whitelisting Trusted Types" section below for more information.
|
93
94
|
|
94
95
|
- `:custom_initializers`: Similar to the `:whitelisted_tags` option, but allows you to provide your own initializers for specified tags rather than using Syck or Psyck. Accepts a hash with string tags for keys and lambdas for values.
|
95
96
|
|
96
|
-
- `:raise_on_unknown_tag` (default: `false`): Represents the highest possible level of paranoia
|
97
|
+
- `:raise_on_unknown_tag` (default: `false`): Represents the highest possible level of paranoia. If the YAML engine encounters any tag other than ones that are automatically trusted by SafeYAML or that you've explicitly whitelisted, it will raise an exception. This may be a good choice if you expect to always be dealing with perfectly safe YAML and want your application to fail loudly upon encountering questionable data.
|
97
98
|
|
98
99
|
All of the above options can be set at the global level via `SafeYAML::OPTIONS`. You can also set each one individually per call to `YAML.load`; an option explicitly passed to `load` will take precedence over an option specified globally.
|
99
100
|
|
@@ -102,7 +103,9 @@ What if I don't *want* to patch `YAML`?
|
|
102
103
|
|
103
104
|
[Excellent question](https://github.com/dtao/safe_yaml/issues/47)! You can also get the methods `SafeYAML.load` and `SafeYAML.load_file` without touching the `YAML` module at all like this:
|
104
105
|
|
105
|
-
|
106
|
+
```ruby
|
107
|
+
require "safe_yaml/load" # instead of require "safe_yaml"
|
108
|
+
```
|
106
109
|
|
107
110
|
This way, you can use `SafeYAML.load` to parse YAML that *you* don't trust, without affecting the rest of an application (if you're developing a library, for example).
|
108
111
|
|
@@ -130,7 +133,7 @@ SafeYAML supports whitelisting certain YAML tags for trusted types. This is hand
|
|
130
133
|
The easiest way to whitelist types is by calling `SafeYAML.whitelist!`, which can accept a variable number of safe types, e.g.:
|
131
134
|
|
132
135
|
```ruby
|
133
|
-
SafeYAML.whitelist!(
|
136
|
+
SafeYAML.whitelist!(Foo, Bar)
|
134
137
|
```
|
135
138
|
|
136
139
|
You can also whitelist YAML *tags* via the `:whitelisted_tags` option:
|
@@ -160,7 +163,7 @@ EOYAML
|
|
160
163
|
Known Issues
|
161
164
|
------------
|
162
165
|
|
163
|
-
If you add SafeYAML to your project and start seeing any errors about missing keys, or you notice mysterious strings that look like `":foo"` (i.e., start with a colon), it's likely you're seeing errors from symbols being saved in YAML format. If you are able to modify the offending code, you might want to consider changing your YAML content to use plain vanilla strings instead of symbols. If not, you may need to set the `:deserialize_symbols` option to `true`, either in calls to `YAML.load` or
|
166
|
+
If you add SafeYAML to your project and start seeing any errors about missing keys, or you notice mysterious strings that look like `":foo"` (i.e., start with a colon), it's likely you're seeing errors from symbols being saved in YAML format. If you are able to modify the offending code, you might want to consider changing your YAML content to use plain vanilla strings instead of symbols. If not, you may need to set the `:deserialize_symbols` option to `true`, either in calls to `YAML.load` or---as a last resort---globally, with `SafeYAML::OPTIONS[:deserialize_symbols]`.
|
164
167
|
|
165
168
|
Also be aware that some Ruby libraries, particularly those requiring inter-process communication, leverage YAML's object deserialization functionality and therefore may break or otherwise be impacted by SafeYAML. The following list includes known instances of SafeYAML's interaction with other Ruby gems:
|
166
169
|
|
@@ -173,12 +176,10 @@ Also be aware that some Ruby libraries, particularly those requiring inter-proce
|
|
173
176
|
|
174
177
|
The above list will grow over time, as more issues are discovered.
|
175
178
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
My intention is to eventually adopt [semantic versioning](http://semver.org/) with this gem, if it ever gets to version 1.0 (i.e., doesn't become obsolete by then). Since it isn't there yet, that means that API may well change from one version to the next. Please keep that in mind if you are using it in your application.
|
179
|
+
Versioning
|
180
|
+
----------
|
180
181
|
|
181
|
-
|
182
|
+
SafeYAML will follow [semantic versioning](http://semver.org/) so any updates to the first major version will maintain backwards compatability. So expect primarily bug fixes and feature enhancements (if anything!) from here on out... unless it makes sense to break the interface at some point and introduce a version 2.0, which I honestly think is unlikely.
|
182
183
|
|
183
184
|
Requirements
|
184
185
|
------------
|
File without changes
|
@@ -9,8 +9,9 @@ module SafeYAML
|
|
9
9
|
])
|
10
10
|
|
11
11
|
def transform?(value)
|
12
|
-
MATCHERS.
|
13
|
-
|
12
|
+
MATCHERS.each_with_index do |matcher, idx|
|
13
|
+
value = value.gsub(/[_,]/, "") if idx == 0
|
14
|
+
return true, Integer(value) if matcher.match(value)
|
14
15
|
end
|
15
16
|
try_edge_cases?(value)
|
16
17
|
end
|
data/lib/safe_yaml/version.rb
CHANGED
data/safe_yaml.gemspec
CHANGED
@@ -6,9 +6,9 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.version = SafeYAML::VERSION
|
7
7
|
gem.authors = "Dan Tao"
|
8
8
|
gem.email = "daniel.tao@gmail.com"
|
9
|
-
gem.description = %q{Parse YAML safely
|
9
|
+
gem.description = %q{Parse YAML safely}
|
10
10
|
gem.summary = %q{SameYAML provides an alternative implementation of YAML.load suitable for accepting user input in Ruby applications.}
|
11
|
-
gem.homepage = "
|
11
|
+
gem.homepage = "https://github.com/dtao/safe_yaml"
|
12
12
|
gem.license = "MIT"
|
13
13
|
gem.files = `git ls-files`.split($\)
|
14
14
|
gem.test_files = gem.files.grep(%r{^spec/})
|
@@ -56,4 +56,9 @@ describe SafeYAML::Transform::ToInteger do
|
|
56
56
|
# sexagesimal
|
57
57
|
subject.transform?("190:20:30").should == [true, 685230]
|
58
58
|
end
|
59
|
+
|
60
|
+
# see https://github.com/dtao/safe_yaml/pull/51
|
61
|
+
it "strips out underscores before parsing decimal values" do
|
62
|
+
subject.transform?("_850_").should == [true, 850]
|
63
|
+
end
|
59
64
|
end
|
metadata
CHANGED
@@ -1,22 +1,26 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: safe_yaml
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Dan Tao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
11
|
+
|
12
|
+
date: 2013-12-27 00:00:00 Z
|
12
13
|
dependencies: []
|
13
|
-
|
14
|
-
|
14
|
+
|
15
|
+
description: Parse YAML safely
|
15
16
|
email: daniel.tao@gmail.com
|
16
17
|
executables: []
|
18
|
+
|
17
19
|
extensions: []
|
20
|
+
|
18
21
|
extra_rdoc_files: []
|
19
|
-
|
22
|
+
|
23
|
+
files:
|
20
24
|
- .gitignore
|
21
25
|
- .travis.yml
|
22
26
|
- CHANGES.md
|
@@ -65,32 +69,34 @@ files:
|
|
65
69
|
- spec/transform/to_integer_spec.rb
|
66
70
|
- spec/transform/to_symbol_spec.rb
|
67
71
|
- spec/yaml_spec.rb
|
68
|
-
homepage:
|
69
|
-
licenses:
|
72
|
+
homepage: https://github.com/dtao/safe_yaml
|
73
|
+
licenses:
|
70
74
|
- MIT
|
71
75
|
metadata: {}
|
76
|
+
|
72
77
|
post_install_message:
|
73
78
|
rdoc_options: []
|
74
|
-
|
79
|
+
|
80
|
+
require_paths:
|
75
81
|
- lib
|
76
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
-
requirements:
|
78
|
-
- -
|
79
|
-
- !ruby/object:Gem::Version
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
80
86
|
version: 1.8.7
|
81
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
-
requirements:
|
83
|
-
- -
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version:
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: "0"
|
86
92
|
requirements: []
|
93
|
+
|
87
94
|
rubyforge_project:
|
88
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.0.14
|
89
96
|
signing_key:
|
90
97
|
specification_version: 4
|
91
|
-
summary: SameYAML provides an alternative implementation of YAML.load suitable for
|
92
|
-
|
93
|
-
test_files:
|
98
|
+
summary: SameYAML provides an alternative implementation of YAML.load suitable for accepting user input in Ruby applications.
|
99
|
+
test_files:
|
94
100
|
- spec/exploit.1.9.2.yaml
|
95
101
|
- spec/exploit.1.9.3.yaml
|
96
102
|
- spec/issue48.txt
|