# GHSA-GMWR-7WMF-MRJM: Unsafe Jackson Default Typing Deserialization in langchain4j-agentic AgenticScopeSerializer

- Database: GitHub
- Severity: CVSS 6.6 (Medium)
- Published: 2026-09-10
- Modified: 2026-09-10

## Affected versions

- dev.langchain4j:langchain4j-agentic (Maven): fixed in 1.5.3-beta11
- dev.langchain4j:langchain4j-agentic (Maven): from 1.6.0-beta12, fixed in 1.11.10-beta19
- dev.langchain4j:langchain4j-agentic (Maven): from 1.12.1-beta21, fixed in 1.18.1-beta28

## Description

## Summary
  In affected versions, `AgenticScopeSerializer.fromJson(String)` restores a `DefaultAgenticScope` using the default `JacksonAgenticScopeJsonCodec`, which enables Jackson default typing (`activateDefaultTyping`)
  with the mapper's default (laissez-faire) `PolymorphicTypeValidator`. Because `DefaultAgenticScope.state` is a `Map<String,Object>`, attacker-controlled JSON can embed polymorphic type metadata (`["<fqcn>",
  {...}]`) for state values and drive instantiation of arbitrary classes. With a suitable gadget on the target classpath this can escalate to remote code execution.

  ## Details
  - **Sink:** `JacksonAgenticScopeJsonCodec` builds a global `ObjectMapper` and calls `mapper.activateDefaultTyping(mapper.getPolymorphicTypeValidator())`. On a plain mapper `getPolymorphicTypeValidator()`
  returns a laissez-faire validator that allows all subtypes, so type metadata in the JSON selects the runtime class.
  - **Carrier:** `DefaultAgenticScope.state` is `Map<String,Object>`; the `Object`-typed values fall under default typing (`OBJECT_AND_NON_CONCRETE`), making the map a polymorphic deserialization sink.
  - **Note on scope:** the top-level object is bound via a `@JsonCreator`, so a `["...DefaultAgenticScope", {...}]` wrapper is rejected at the root and never reaches the sink. A working exploit must use the real
  top-level envelope and place the gadget inside a `state` value (see PoC).

  Vulnerable sink (affected versions):
  ```java
  // JacksonAgenticScopeJsonCodec
  static ObjectMapper agenticScopeJsonSerializer() {
      ObjectMapper mapper = agenticScopeJsonMapperBuilder().build();
      mapper.activateDefaultTyping(mapper.getPolymorphicTypeValidator()); // allow-all validator
      return mapper;
  }

  @Override
  public DefaultAgenticScope fromJson(String json) {
      return MAPPER.readValue(json, DefaultAgenticScope.class); // instantiates Object-typed state values
  }                                                                                         
  ```

  ## Preconditions (both required for exploitation)
  1. The consuming application feeds **untrusted or tamperable** AgenticScope JSON into `AgenticScopeSerializer.fromJson` — e.g. persisted session/workflow-recovery state in a low-privilege-writable store, or
  cross-service scope messages.
  2. A usable deserialization **gadget class is present on the target classpath**.

  The library itself never passes untrusted data to `fromJson`; only application code can create the untrusted-input path.

## Proof of concept
  The payload must use the real top-level envelope and carry the gadget in a `state` value:
  ```json
  {
    "memoryId": "attacker",
    "kind": "PERSISTENT",
    "state": ["java.util.concurrent.ConcurrentHashMap", {
      "exploit": ["<gadget-fqcn-on-classpath>", { /* gadget-specific properties */ }]
    }],
    "agentInvocations": ["java.util.Collections$SynchronizedRandomAccessList", []],
    "context": ["java.util.Collections$SynchronizedRandomAccessList", []]
  }
  ```
  Passing this to `AgenticScopeSerializer.fromJson(...)` instantiates the class named under `state`. In a safe test, a class with an observable constructor side effect confirms instantiation; on a classpath with
  a real Jackson gadget, gadget-specific effects (including RCE) may occur.

  ## Impact
  Instantiation of attacker-chosen classes from JSON. With a classpath gadget this can reach remote code execution; without one, it can still cause denial of service, SSRF, file access, or object-state
  pollution, depending on how the application persists and trusts `AgenticScope.state`.

  ## Remediation

  Fixed in **1.18.1-beta28**, and backported to **1.11.10-beta19** (1.11.x LTS) and **1.5.3-beta11** (1.5.x LTS). Upgrade to one of these or later.

  The 1.12.x line (`1.12.1-beta21`, `1.12.2-beta22`) received no backport; users on that line should move to `1.18.1-beta28` or later.

  The default codec no longer uses laissez-faire polymorphic typing. Instead:

  - Default typing is validated by a strict allow-list (`ConfigurablePolymorphicTypeValidator`) that permits only primitive wrappers, `String`, `Boolean`, `Character`, enums, controlled JDK collection/math
  types, and the specific langchain4j message/data and internal types actually serialized. Everything else is denied.
  - Array type ids (`"[L...;"`) are validated by their element type, so a disallowed class cannot be smuggled in wrapped as an array.
  - Denied types raise a clear `UnserializableAgenticScopeException` instead of instantiating.

  ### Breaking Changes

  Applications that store their own domain objects in `AgenticScope` state must now allow-list those types before deserialization, otherwise `fromJson` throws `UnserializableAgenticScopeException`:

  ```java
  AgenticScopeSerializer.allowDeserializationType(com.acme.Order.class);
  // or, for a whole package:
  AgenticScopeSerializer.allowDeserializationPackagePrefix("com.acme.");
  ```

  Registration is process-wide and permanent, and must occur before the `fromJson` call that encounters the type.

  As always, treat `fromJson` input as security-sensitive: only deserialize trusted data unless a hardened codec and allow-list are in place.

## References

- https://github.com/langchain4j/langchain4j/security/advisories/GHSA-gmwr-7wmf-mrjm

Page: https://cve.now/GHSA-GMWR-7WMF-MRJM

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
