Skip to main content
Menu
Advisories

Summary The request-derived trust boundary added in 2.x is enforced by object identity, and only Map and List containers are ever marked

GHSA-M82Q-JGC3-9GC9Published Updated GitHub

Description

The request-derived trust boundary added in 2.x is enforced by object identity, and only Map and List containers are ever marked. A String that a mock feature pulls out of the request (request.poc) is a different object, so isRequestDerived returns false, the guard does not fire, and the attacker's #(...) text is evaluated. I ran this against the published Maven Central artifact io.karatelabs:karate-core:2.1.1 on JDK 21 and got OS command execution via karate.exec. The same shape is present in 2.1.0.

Details

Three pieces:

  • ScenarioRuntime.markRequestDerived(...) deep-walks the request body and adds objects to a requestDerived identity set, but it only ever adds Map and List containers. Scalars inside those containers are not added.
  • ScenarioRuntime.isRequestDerived(...) answers by identity lookup in that same set.
  • StepExecutor.processEmbeddedExpressions(value, lenient) short-circuits only when runtime.isRequestDerived(value) is true. Otherwise, if the value is a String, it falls through to processEmbeddedString(...), which calls runtime.eval(...) on the #(...) text.

The untrusted data gets in through MockHandler, which binds request lazily via markRequestDerived(runtime, currentRequest.getBodyConverted()). So the marking is correct for the container the handler hands over, and wrong for everything a step extracts from it.

The precondition on the target side is the shape of the mock feature. The vulnerable shape is a step that reads a scalar out of request inside a JS expression:

Feature: echo-extract

Scenario: pathMatches('/echo')
* def response = ({ data: request.poc })

Note the parentheses. The plain JSON form * def response = { data: request.poc } is not the trigger and does not fire this.

PoC

The PoC script resolves io.karatelabs:karate-core:2.1.1 from Maven Central, so there is no karate source checkout involved, compiles a small Java driver, starts a real MockServer on an ephemeral TCP port, and drives it with java.net.http.HttpClient. Run on JDK 21; KARATE_VERSION=2.1.0 also reproduces. The script prints the resolved jar location so the artifact under test is not in doubt.

With the feature above running, a POST body of {"poc": "#(karate.exec('id'))"} gets the expression evaluated inside the mock JVM. karate.read('classpath:...') and karate.read('file:/etc/hosts') also work and read server-side files.

The last block is the one that settles the argument. It picks a marker path under java.io.tmpdir, deletes it, prints whether it exists, sends {"poc": "#(karate.exec(['/bin/sh','-c','id -un > <marker> 2>&1']))"}, then prints whether it exists again and dumps the contents. Measured result on my run: the marker did not exist before the request, existed after it, and contained the username that id -un prints for the account running the mock. A file that a shell created on disk during an HTTP request is not a classpath read. I have the script and the measured before and after, not a saved console transcript, so I am describing what I observed rather than pasting one.

Negative controls I checked so you do not have to:

  • * def response = request, assigning the request container itself, is correctly guarded. isRequestDerived returns true on the container and the whole subtree comes back verbatim.
  • Java.type('java.lang.System') fails. Java interop is off by default in the mock engine, and this bug does not turn it on.
  • karate.read('/etc/hosts'), the bare absolute path with no file: prefix, does not resolve.
  • The opt-in requestExpressionsEnabled(true) builder flag is a separate, deliberate switch. This report is about the default, where that flag is off.

I am happy to send the script directly.

Impact

Anyone who can send an HTTP request to a running Karate Mock Server, with no authentication and no other prerequisite on the attacker side, gets arbitrary command execution as the user running the mock, provided the mock feature uses the extracting shape above.

I am not scoring this as a production-server issue and would not argue with a maintainer who weighs it as test infrastructure. Mock servers do get run in shared CI and in dev environments reachable from a network, which is why I am reporting it rather than filing it as a note.

Suggested fix

The identity set is the wrong mechanism, since extraction always produces a new object. The smallest change that keeps the current design is to have markRequestDerived also add scalar Strings found inside a request-derived container, gated on the string containing #( so the common case costs nothing. The sturdier change is to stop asking about the value and instead carry a trust flag down the walk in processEmbeddedExpressions, so an extracted scalar inherits the taint of the container it came from.

Whichever way you go, the other request-derived scalars exposed to the mock runtime (requestUri, requestPath, headers) want the same treatment, or the same trick works through a different binding.

Why this is not GHSA-2c85-rfcc-g74j

That advisory is the reason markRequestDerived and isRequestDerived exist. Its fix stops the mock engine from evaluating embedded expressions in request data by marking the Map and List containers the handler binds, and short-circuiting processEmbeddedExpressions when it sees one of those exact objects.

What it does not cover is extraction. request.poc yields a String that was never in the identity set, so isRequestDerived returns false on it and the fall-through to processEmbeddedString is reached exactly as before the fix. The guard is intact and the payload goes around it.

Severity

Low. The Karate Mock Server is developer test tooling, documented as intended for trusted networks only and never for exposure to untrusted clients. Exploitation additionally requires the mock feature to be authored in a specific shape — extracting a request scalar inside a JS expression — which the attacker neither controls nor can discover. This is an incomplete-fix variant of GHSA-2c85-rfcc-g74j, which was published as Low; the same weighting applies. The reporter concurs that this is not a production-server issue.

Fixed in 2.1.2 by tracking untrusted request strings by value, not just by container identity. Mocks that need the previous behavior can opt in with configure requestExpressionsEnabled = true.

I used AI assistance for the audit and drafting. I manually verified the PoC compiling and running against the Maven Central 2.1.1 jar on JDK 21, the karate.exec marker file appearing on disk with the expected contents, and the negative controls above (the container form staying verbatim, Java.type failing, the bare absolute path not resolving).

Affected versions

References

GitHub · karatelabs/karate