github / github/codeql

`rb/unsafe-deserialization`: YAML.load - false positive since Psych 4.0

Open
#10,151 1 comment 0 reactions 0 assignees View on GitHub
false-positive Ruby
Dominant language
CodeQL
Stars
10.1k
Forks
2.1k
Avg merge
2d 15h
Merged PRs (30d)
141

Description

**Description of the false positive**

Good news: `YAML.load` got safer :wink:

Since [Psych 4.0](https://www.ctrl.blog/entry/ruby-psych4.html) no arbitrary Ruby classes are instantiated when `YAML.load` is used. There's now a method called `YAML.unsafe_load` to get the old behavior back.
This change in behavior affects the `rb/unsafe-deserialization` query.

Sidenote:
Ruby 3.1 (released in December 2021) depends on Psych 4.0 by default. (Projects still can use older Psych versions by defining something like `psych ~>3.0` in their Gemfiles.)

Following ideas:
* Add a note to unsafe deserialization results that concern `YAML.load`. E.g., "YAML.load is insecure in Psych versions before 4.0"
* Add a source for `YAML.unsafe_load`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.