safe_yaml 0.8.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/safe_yaml.rb +20 -0
- data/lib/safe_yaml/resolver.rb +1 -3
- data/lib/safe_yaml/syck_node_monkeypatch.rb +1 -1
- data/lib/safe_yaml/version.rb +1 -1
- metadata +1 -1
data/lib/safe_yaml.rb
CHANGED
@@ -27,6 +27,26 @@ module SafeYAML
|
|
27
27
|
def restore_defaults!
|
28
28
|
OPTIONS.clear.merge!(DEFAULT_OPTIONS)
|
29
29
|
end
|
30
|
+
|
31
|
+
def tag_safety_check!(tag)
|
32
|
+
return if tag.nil?
|
33
|
+
if OPTIONS[:raise_on_unknown_tag] && !OPTIONS[:whitelisted_tags].include?(tag) && !tag_is_explicitly_trusted?(tag)
|
34
|
+
raise "Unknown YAML tag '#{tag}'"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
if YAML_ENGINE == "psych"
|
39
|
+
def tag_is_explicitly_trusted?(tag)
|
40
|
+
false
|
41
|
+
end
|
42
|
+
|
43
|
+
else
|
44
|
+
TRUSTED_TAGS = ["tag:yaml.org,2002:str"].freeze
|
45
|
+
|
46
|
+
def tag_is_explicitly_trusted?(tag)
|
47
|
+
TRUSTED_TAGS.include?(tag)
|
48
|
+
end
|
49
|
+
end
|
30
50
|
end
|
31
51
|
|
32
52
|
module YAML
|
data/lib/safe_yaml/resolver.rb
CHANGED
@@ -3,7 +3,7 @@ monkeypatch = <<-EORUBY
|
|
3
3
|
def safe_transform
|
4
4
|
if self.type_id
|
5
5
|
return unsafe_transform if SafeYAML::OPTIONS[:whitelisted_tags].include?(self.type_id)
|
6
|
-
|
6
|
+
SafeYAML.tag_safety_check!(self.type_id)
|
7
7
|
end
|
8
8
|
|
9
9
|
SafeYAML::SyckResolver.new.resolve_node(self)
|
data/lib/safe_yaml/version.rb
CHANGED