Ask Your Question
3

How can Gradle be prompted to conduct checksum validation on cached artifacts in the event of rewritten dependencies on repositories, specifically to prevent dependency chain attacks?

asked 2021-10-26 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-04-27 19:00:00 +0000

nofretete gravatar image

Gradle has built-in support for checksum validation on cached artifacts. To enable this feature to prevent dependency chain attacks, you can add the following configuration to your build.gradle file:

configurations.all {
    resolutionStrategy {
        cacheChangingModulesFor 0, 'seconds'
        eachDependency { DependencyResolveDetails details ->
            def requested = details.requested
            def from = details.from
            def found = details.resolved

            if (requested.moduleVersion != found.moduleVersion) {
                def newModule = "${requested.module}:${requested.name}:${found.version}"
                def message = "Warning: ${newModule} was resolved from ${from.module}:${from.name}:${from.version} and is now resolved from ${found.module}:${found.name}:${found.version}. This could be a potential security vulnerability."
                logger.warn(message)
                throw new GradleException(message)
            }
        }
    }
}

This configuration ensures that Gradle only cache non-changing modules for 0 seconds, which forces Gradle to always check the remote repository for new modules. Additionally, this configuration checks if the resolved dependency is the same as the requested dependency by comparing their respective module versions. If a different module version is found during resolution, Gradle raises a warning and fails the build. This feature helps mitigate the likelihood of dependency chain attacks.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-10-26 11:00:00 +0000

Seen: 14 times

Last updated: Apr 27 '22