-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more negative patterns to exclude cases of reading from a file fo…
…r Yaml bad deserialization (#3296) * Add more negative patterns to exclude cases of reading from a file * Update .fixed file for autofix test case
- Loading branch information
Showing
3 changed files
with
91 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,43 @@ | ||
def bad_deserialization | ||
def bad_deserialization | ||
|
||
o = Klass.new("hello\n") | ||
data = YAML.dump(o) | ||
# ruleid: bad-deserialization-yaml | ||
obj = Psych.safe_load(data) | ||
o = Klass.new("hello\n") | ||
data = YAML.dump(o) | ||
# ruleid: bad-deserialization-yaml | ||
obj = Psych.safe_load(data) | ||
end | ||
|
||
end | ||
def ok_deserialization | ||
o = Klass.new("hello\n") | ||
data = YAML.dump(o) | ||
# ok: bad-deserialization-yaml | ||
obj = YAML.load(data, safe: true) | ||
|
||
def ok_deserialization | ||
o = Klass.new("hello\n") | ||
data = YAML.dump(o) | ||
# ok: bad-deserialization-yaml | ||
obj = YAML.load(data, safe: true) | ||
filename = File.read("test.txt") | ||
data = YAML.dump(filename) | ||
# ok: bad-deserialization-yaml | ||
YAML.load(filename) | ||
|
||
filename = File.read("test.txt") | ||
data = YAML.dump(filename) | ||
# ok: bad-deserialization-yaml | ||
YAML.load(filename) | ||
# ok: bad-deserialization-yaml | ||
YAML.load(File.read("test.txt")) | ||
|
||
# ok: bad-deserialization-yaml | ||
YAML.load(File.read("test.txt")) | ||
end | ||
# ok: bad-deserialization-yaml | ||
obj = YAML::load(ERB.new(File.read("test.yml")).result) | ||
|
||
# ok: bad-deserialization-yaml | ||
obj = YAML::load(ERB.new(File.read("test.yml"))) | ||
|
||
template = ERB.new(File.read("test.yml")) | ||
# ok: bad-deserialization-yaml | ||
obj = YAML::load(template) | ||
|
||
template = ERB.new(File.read("test.yml")).result | ||
# ok: bad-deserialization-yaml | ||
obj = YAML::load(template) | ||
|
||
template = ERB.new(File.read("test.yml")) | ||
# ok: bad-deserialization-yaml | ||
obj = YAML::load(template.result) | ||
|
||
# ok: bad-deserialization-yaml | ||
obj = YAML.load(File.read(File.join(Pathname.pwd, "hello.yml"))) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,43 @@ | ||
def bad_deserialization | ||
def bad_deserialization | ||
|
||
o = Klass.new("hello\n") | ||
data = YAML.dump(o) | ||
# ruleid: bad-deserialization-yaml | ||
obj = YAML.load(data) | ||
o = Klass.new("hello\n") | ||
data = YAML.dump(o) | ||
# ruleid: bad-deserialization-yaml | ||
obj = YAML.load(data) | ||
end | ||
|
||
end | ||
def ok_deserialization | ||
o = Klass.new("hello\n") | ||
data = YAML.dump(o) | ||
# ok: bad-deserialization-yaml | ||
obj = YAML.load(data, safe: true) | ||
|
||
def ok_deserialization | ||
o = Klass.new("hello\n") | ||
data = YAML.dump(o) | ||
# ok: bad-deserialization-yaml | ||
obj = YAML.load(data, safe: true) | ||
filename = File.read("test.txt") | ||
data = YAML.dump(filename) | ||
# ok: bad-deserialization-yaml | ||
YAML.load(filename) | ||
|
||
filename = File.read("test.txt") | ||
data = YAML.dump(filename) | ||
# ok: bad-deserialization-yaml | ||
YAML.load(filename) | ||
# ok: bad-deserialization-yaml | ||
YAML.load(File.read("test.txt")) | ||
|
||
# ok: bad-deserialization-yaml | ||
YAML.load(File.read("test.txt")) | ||
end | ||
# ok: bad-deserialization-yaml | ||
obj = YAML::load(ERB.new(File.read("test.yml")).result) | ||
|
||
# ok: bad-deserialization-yaml | ||
obj = YAML::load(ERB.new(File.read("test.yml"))) | ||
|
||
template = ERB.new(File.read("test.yml")) | ||
# ok: bad-deserialization-yaml | ||
obj = YAML::load(template) | ||
|
||
template = ERB.new(File.read("test.yml")).result | ||
# ok: bad-deserialization-yaml | ||
obj = YAML::load(template) | ||
|
||
template = ERB.new(File.read("test.yml")) | ||
# ok: bad-deserialization-yaml | ||
obj = YAML::load(template.result) | ||
|
||
# ok: bad-deserialization-yaml | ||
obj = YAML.load(File.read(File.join(Pathname.pwd, "hello.yml"))) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters