Gradle can resolve dependencies from, and publish to, Maven and Ivy repositories accessed over SFTP (sftp:// URLs), authenticating with a username and password. SSH authenticates the server to the client with the server's host key, which the client checks against the keys it already knows, usually in ~/.ssh/known_hosts. This advisory is about a vulnerability in how Gradle connects to SFTP repositories.
Gradle accepts any host key presented by the server. It does not read known_hosts, and no setting enables verification. An attacker who can make the build connect to them instead of the real server, through an on-path network position, DNS or ARP spoofing, or by taking over the address of a decommissioned server, can impersonate the repository without any warning to the user. The attacker can then:
Checksum files fetched from the repository offer no protection, since the attacker serves them too. Builds using dependency verification detect substituted artifacts that are already listed in their verification metadata, but not the theft of the repository password, nor tampering with publications.
Only builds that declare an sftp:// repository are affected. A demonstration against Gradle's test SFTP server shows a build succeeding, and sending the password, after the server's host key was replaced.
Gradle now verifies the host key of SFTP repository servers against the OpenSSH known hosts files: ~/.ssh/known_hosts and /etc/ssh/ssh_known_hosts, or %ProgramData%\ssh\ssh_known_hosts on Windows. A connection to a server whose host is not listed, or whose key does not match the one listed, fails before the repository credentials are sent. The error names the server, the type and SHA-256 fingerprint of the key it presented, and how to add it.
This changes the behavior of builds that use SFTP repositories. Gradle does not record the key of a server it connects to for the first time, so the host key of every SFTP repository server must be listed before the build runs. Check the fingerprint with the server's administrator, then add the key, for example with ssh-keyscan -p <port> <host> >> ~/.ssh/known_hosts. Host certificates (@cert-authority entries) and wildcard host patterns are not supported.
To keep connecting to a server without verifying its host key, set allowInsecureProtocol = true on the repository. That repository then remains exposed to this vulnerability.
| Fix version | Availability |
|---|---|
| 9.9.2 | OSS |
| 9.8.4 | Gradle Security Subscription |
| 9.7.4 | Gradle Security Subscription |
| 9.6.4 | Gradle Security Subscription |
| 9.5.4 | Gradle Security Subscription |
| 9.4.4 | Gradle Security Subscription |
| 9.3.4 | Gradle Security Subscription |
| 9.2.4 | Gradle Security Subscription |
| 8.14.8 | OSS |
| 7.6.9 | Gradle Security Subscription |
Upgrading Gradle is our recommended fix.
If you cannot upgrade immediately:
Gradle does not log the host key of SFTP servers above debug level. With --debug, the SSH library logs the host and the key type it accepted, but not the key fingerprint, and only when the first SFTP connection of the Gradle daemon was made at debug level.
To check whether resolved artifacts were substituted, compare the files in the Gradle dependency cache with the repository over a trusted channel. The cache stores each file under <Gradle user home>/caches/modules-2/files-2.1/<group>/<module>/<version>/<sha1>/, where <sha1> is the SHA-1 checksum of the file as it was downloaded.
To check publications, compare the artifacts on the repository server with the build outputs, and check the server's authentication logs for the publishing account: a publication that reported success but left no login on the server reached another host.
A fixed version reports a server it cannot authenticate instead of connecting to it. Could not verify the identity of SFTP server at sftp://<host>:<port>: its key does not match the one listed for this host in the SSH known hosts files. means that the key of a known server changed, through a legitimate key rotation or an impersonation attempt. The message includes the fingerprint of the presented key, to compare with the one of the real server.
If an SFTP repository was used over a network you do not fully trust, rotate its credentials.
[!IMPORTANT] The lack of such traces cannot be used to conclude no such attack was performed. Their presence is not a confirmation that an attack happened, but an indication that more investigations are needed.
More about this type of vulnerabilities:
{
"coverage": "partial",
"coverage_exclusions": [
"legacy_package_image_owner"
]
}