Skip to content
Memory corruption Advisory Advanced CVE-2022-29181

GHSL-2022-031_GHSL-2022-032: Type confusion in Nokogiri leads to memory leak or DoS - CVE-2022-29181

Two type confusion vulnerabilities in Nokogiri's SAX parser context functions allow an attacker who controls the object passed to parse_memory to supply a non-string value, causing a crash or potential memory disclosure. This can lead to denial of service or information disclosure.

agustingianni Follow

Originally disclosed on GitHub Security Lab

Two type confusion issues while processing malicious data can be used to leak the contents of memory or cause a denial-of-service.

agustingianni, on GitHub Security Lab

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The parse_memory functions in xml_sax_parser_context.c and html4_sax_parser_context.c use RSTRING_LEN on the data argument without first verifying that it is a Ruby String (T_STRING), leading to type confusion.

Impact

This issue may lead to DoS or Information Disclosure.

What the attacker needed

Attacker controls input to parse_memory

The fix

The maintainers fixed the issues and released an advisory.

How it was found

  1. Create a Nokogiri SAX parser instance.
  2. Call parse with a non-string value, such as an integer.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Nokogiri is a Ruby library for parsing XML and HTML. The bug is that a function expected to receive a string did not check the type of the input, so if an attacker passed a number instead, the program would treat it as a memory address and crash. This could be used to crash a server or, in some cases, leak memory contents.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by agustingianni

View all

24 more disclosed reports, best first.

More from GitHub Security Lab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.