Critical GitLab RCE Flaw Exploits Oj JSON Parser Bugs Through Jupyter Notebook Diffs
A newly disclosed remote code execution (RCE) chain has exposed a critical security weakness in GitLab Community Edition (CE) and Enterprise Edition (EE), leveraging two previously undiscovered memory corruption vulnerabilities in the widely used Oj (Optimized JSON) parser for Ruby.
Security researchers at Depthfirst revealed that the flaws remained hidden for nearly five years before being linked to GitLab’s Jupyter Notebook diff rendering functionality.
The discovery highlights how native C extensions embedded within otherwise memory-safe programming environments can introduce severe security risks when not rigorously audited.
Critical GitLab RCE Flaw Exploits Oj JSON Parser
The attack targets GitLab’s built-in support for rendering differences between Jupyter Notebook (.ipynb) files. Whenever a user commits a notebook file to a repository, GitLab’s internal ipynbdiff component parses the notebook’s JSON content using Oj::Parser.usual.parse to generate a human-readable comparison.
Although this feature appears harmless, the parsing operation executes inside GitLab’s Puma worker processes under the git user account, creating an unexpected attack surface.
Researchers demonstrated that any authenticated project member with permission to push code to a repository could exploit the vulnerability without requiring administrator privileges, user interaction, or social engineering.
The exploitation chain begins with an out-of-bounds write vulnerability affecting Oj’s nesting-depth tracking logic. The parser maintains a fixed 1,024-byte stack buffer to track nested JSON structures but fails to validate excessive nesting depth.
By crafting a malicious notebook containing deeply nested arrays, an attacker can overwrite memory beyond the buffer with repeated 0x01 bytes.
Eventually, this corrupts an internal buffer pointer known as buf.head, creating a controlled memory corruption condition.
Researchers further refined the exploit using a specially crafted 4,001-digit integer and a 446-element array to manipulate jemalloc’s memory allocation behavior.
This heap grooming technique allowed attacker-controlled data to overwrite Oj’s internal callback pointer (p->start), laying the groundwork for arbitrary code execution.
A second vulnerability provides the information disclosure necessary to bypass modern exploit mitigations. Oj incorrectly stores oversized JSON object key lengths by truncating a 64-bit value into a 16-bit field, resulting in a heap memory disclosure.
Instead of safely processing the oversized key, the parser unintentionally leaks 29 bytes of raw internal memory from the Key structure through GitLab’s notebook diff output.
Among the leaked data is a valid heap pointer, providing attackers with a reliable memory reference for subsequent exploitation.
This memory disclosure significantly weakens Address Space Layout Randomization (ASLR). GitLab’s Puma workers operate in preloaded cluster mode, meaning forked worker processes inherit identical library memory layouts.
By analyzing the leaked heap pointer and comparing it with known memory offsets, researchers successfully brute-forced the base addresses of libc and libruby within minutes using a callback-controlled probing technique. Once ASLR protections were defeated, attackers could reliably redirect execution flow.
The final exploitation stage uses two malicious notebook files processed within the same diff request. The first notebook prepares the corrupted callback pointer, while the second immediately triggers its execution during another parsing operation.
This sequence hijacks program execution and redirects control flow into the standard system() function, allowing arbitrary operating system commands to execute with the privileges of the git user.
Although the exploit does not immediately grant root access, compromising the GitLab service account can enable repository manipulation, credential theft, lateral movement, and potentially full server compromise depending on the deployment environment.
GitLab has released security updates addressing the vulnerability. Affected GitLab CE and EE versions 15.2.0 through 18.10.7 should be upgraded to 18.10.8, versions 18.11.0 through 18.11.4 should move to 18.11.5, and versions 19.0.0 through 19.0.1 should be updated to 19.0.2. Additionally, the vulnerable Oj gem versions 3.13.0 through 3.17.1 have been patched in version 3.17.3.
Beyond this exploit chain, researchers identified nine separate CVEs affecting the Oj library, including buffer overflows, use-after-free conditions, and integer overflow vulnerabilities across its parser, loader, and dumper components.
The findings reinforce the importance of thoroughly auditing native C extensions used by high-level programming languages, as memory safety issues within these components can undermine the security guarantees of otherwise memory-safe application ecosystems.
Organizations running self-managed GitLab instances should prioritize patching immediately and monitor repositories for suspicious notebook commits that could indicate exploitation attempts.
No Comment! Be the first one.