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.
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.
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
- Create a Nokogiri SAX parser instance.
- 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.