Gradle's dependency verification checks every dependency and plugin a build downloads against checksums and trusted signing keys recorded in gradle/verification-metadata.xml. Once that file is written and reviewed, a build fails if a dependency is replaced by different content, for instance after a repository compromise. Changing modules, such as -SNAPSHOT versions, are excluded because their content changes by design. This advisory is about a vulnerability in dependency verification.
The exclusion also applies to changing modules that a build does not declare itself, but reaches through the metadata of another dependency. When a release the build depends on declares a dependency on a -SNAPSHOT version, Gradle verifies the release but neither verifies the snapshot nor records anything for it when generating verification-metadata.xml. Reviewing the changes to that file does not reveal the snapshot.
An attacker who publishes such a release, or who controls the coordinates of the snapshot it depends on, can serve harmless content while the release is reviewed and adopted, then replace the snapshot at any later time. Every later build resolves the new content without a verification failure. When the snapshot is on the classpath of a plugin or of build logic, or its code is run by a task such as tests, the attacker's code runs with the privileges of the user running the build. This exposes the secrets available to the build, including repository and publishing credentials.
Only builds that use dependency verification are affected: a build without it does not verify any dependency, snapshot or not. Among those, builds that declare a repository serving snapshots, such as a snapshot repository, JitPack or an internal repository manager proxying one, are at risk. Maven Central does not serve snapshots, and Gradle does not use repositories declared in POM files, so a build resolving only from Maven Central is not exposed. The Gradle Plugin Portal does not support snapshots either: the content of a version published there cannot change, even when the version is named -SNAPSHOT, so plugins and dependencies resolved from it cannot be replaced this way.
With dependency verification enabled, Gradle now verifies changing modules like any other module, whether the build declares them itself or reaches them through another dependency. Their metadata and artifacts are checked against verification-metadata.xml, and --write-verification-metadata records them.
This changes the behavior of builds that use dependency verification and resolve changing modules, including snapshots they declare themselves. Such a build fails with Dependency verification failed until its changing modules are covered by verification-metadata.xml. The checksum of a snapshot changes each time it is published, so prefer verifying signatures and trusting the keys that sign them. Snapshots you accept without verification must be trusted explicitly, which makes the exemption visible to reviewers of that file:
<trusted-artifacts>
<trust group="com.example" version=".*-SNAPSHOT" regex="true"/>
</trusted-artifacts>
| 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:
Fail the build on changing versions. failOnChangingVersions() rejects changing modules anywhere in the dependency graph, including those brought in by other dependencies. Apply it to the build script classpath as well, for example in an init script:
allprojects {
configurations.configureEach {
resolutionStrategy.failOnChangingVersions()
}
buildscript.configurations.configureEach {
resolutionStrategy.failOnChangingVersions()
}
}
It cannot be combined with dependency locking on the same configuration.
Restrict what snapshot repositories can serve. Use repository content filtering to limit each repository that serves snapshots to the groups you expect from it, and declare the other repositories with mavenContent { releasesOnly() }.
Snapshots in the dependency graph are listed with a -SNAPSHOT version in the output of gradle dependencies and in build scans. gradle dependencyInsight --dependency MODULE shows which dependency brought a given snapshot in.
The Gradle dependency cache keeps each downloaded file under <Gradle user home>/caches/modules-2/files-2.1/<group>/<module>/<version>/<sha1>/. Several <sha1> directories under a snapshot version show that its content changed over time.
[!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"
]
}