A Gradle client (the gradle/gradlew CLI or an IDE using the Tooling API) looks up running Gradle daemons in a registry file under the Gradle user home, then connects to an idle daemon over a loopback TCP connection and sends it the build to run. The client authenticates itself to the daemon with a secret token, but the daemon is not authenticated to the client, and the client does not check that the daemon process recorded in the registry is still running. This advisory is about a vulnerability on this communication channel.
When a daemon terminates without removing itself from the registry, for example when it is killed with kill -9, stopped by the out-of-memory killer or crashes, its loopback port becomes free while the registry still points to it. Another local user who binds that port receives the next build request from the victim's client. That request contains the client's environment variables, system properties and standard input, which commonly hold credentials and CI tokens. The attacker can then answer with crafted messages that the client deserializes:
Code execution in the client runs with the privileges of the user running the build. This has been demonstrated with a proof-of-concept. This advisory does not publish the proof-of-concept.
Builds running on shared / multi-user build hosts are the most at risk. The vulnerability requires a daemon to have terminated abnormally, leaving a stale entry in the registry, and the attacker to listen on that daemon's port when the victim next starts a build or synchronizes a project in an IDE.
This vulnerability is not exploitable from a remote network connection.
The client and the daemon now authenticate each other as soon as a connection opens, before any message is exchanged. The connection token in the registry holds two secrets. The client proves it holds the first one, and only then does the daemon answer with the second. The client checks that answer before it sends anything else. A process listening on the port of a terminated daemon cannot produce the daemon's secret. The client therefore drops the connection, removes the stale entry from the registry, and uses or starts another daemon. That process only receives the client's half of the token of a daemon that no longer exists.
The fix depends on the Gradle version used by the build, not on the Tooling API version of the IDE.
| Fix version | Availability |
|---|---|
| 9.9.1 | OSS |
| 9.8.3 | Gradle Security Subscription |
| 9.7.3 | Gradle Security Subscription |
| 9.6.3 | Gradle Security Subscription |
| 9.5.3 | Gradle Security Subscription |
| 9.4.3 | Gradle Security Subscription |
| 9.3.3 | Gradle Security Subscription |
| 9.2.3 | Gradle Security Subscription |
| 8.14.7 | OSS |
| 7.6.8 | Gradle Security Subscription |
Upgrading Gradle is our recommended fix.
If you cannot upgrade immediately:
<Gradle user home>/daemon/<Gradle version>/registry.bin. This is safe while daemons are running. Clients no longer find the running daemons and start new ones, and the unregistered daemons stop after their idle timeout (3 hours by default). On an affected version, do not use gradle --status or gradle --stop for this: both connect to every daemon in the registry, including stale entries.If you cannot apply these mitigations, restrict which users and processes share a host with your builds until you can upgrade.
Gradle's output does not tell a process squatting a daemon's port apart from a daemon whose port is free. Look for the conditions of the attack on the build host instead:
<Gradle user home>/daemon/<Gradle version>/daemon-<pid>.out.log, that does not end with Daemon vm is shutting down... even though process <pid> is no longer running. Its port is on the line Daemon starting at: …, with address: [… port:<port>, …].lsof -nP -iTCP:<port> -sTCP:LISTEN.[!IMPORTANT] These checks reveal the conditions for the attack, not the attack itself: by default, Gradle does not record which process a client sent its request to. Daemons also terminate abnormally for ordinary reasons, such as the out-of-memory killer, a crash or a machine reboot, so a log file without a shutdown line is not evidence of an attack. A squatting process only shows while it is still listening, and Gradle deletes daemon log files after 14 days by default, so finding neither does not rule out an attack.
More about this type of vulnerabilities:
{
"coverage": "partial",
"coverage_exclusions": [
"legacy_package_image_owner"
]
}