Summary
HTTPX can deserialize JSON responses unsafely when its decoder uses Oj in the default object mode. If an attacker can influence a URL the application fetches and parses with HTTPX::Response#json, they may cause Ruby objects to be instantiated; with a suitable gadget chain, this could lead to remote code execution.
Affected context
The issue affects applications using the HTTPX Ruby gem's JSON response parsing when Oj is loaded and multi_json is absent, causing the decoder to fall back to Oj.load without a restricted mode. Risk arises when an attacker can influence the fetched response and the application calls .json on it. The vulnerability is reported in HTTPX 1.9.0.
Exploit preconditions
- Attack surface: An application fetches and parses an HTTP response using HTTPX.
- Required access: The attacker must be able to control or influence the URL or the response returned from it.
- Trigger point: The application parses the response by calling
HTTPX::Response#json. - Why exploitation is possible: With Oj loaded and
multi_jsonabsent, the decoder usesOj.loadin its default object mode, which can instantiate loaded Ruby classes and resolve class or module references. Remote code execution may require a suitable gadget chain.
Why this happens
The decoder passes response content to a general-purpose deserializer without selecting a restricted parsing mode. Oj's default object mode can interpret serialized data as instructions to instantiate Ruby objects and populate their instance variables. This is CWE-502: Deserialization of Untrusted Data: attacker-influenced input is processed in a way that permits unsafe object construction.
Potential impact
- Attacker-influenced responses could cause unexpected Ruby objects to be instantiated in the application process.
- A suitable gadget chain could allow arbitrary code execution.
- The application's data or runtime could be compromised, depending on its privileges and accessible resources.
General mitigation guidance
Mitigation centers on treating remote response bodies as untrusted data and preventing general-purpose object construction during parsing.
Common defensive patterns include:
- Use JSON parsing modes or libraries that produce only basic data types, such as hashes, arrays, strings, numbers, booleans, and null values.
- Avoid deserializing network responses into arbitrary application objects.
- Validate parsed data against an explicit schema before using it.
- Reduce the influence untrusted parties have over fetched URLs and response sources.
- Run applications with least privilege to limit the consequences of a parser compromise.
How teams detect issues like this
High-level detection approaches include:
- Static analysis for deserialization calls that use untrusted response bodies without a restricted mode.
- Code review of HTTP client flows that pass response content directly to object-capable parsers.
- Dependency and configuration checks for combinations where Oj is loaded and alternative JSON decoder paths are unavailable.
- Policy checks requiring network data to be parsed into basic data types and validated before use.
Automated code review tools may help identify risky parser usage and data flows.

