CVE-2021-32751 Arbitrary code execution via specially crafted environment variables

High 7.5 Published Updated

Attackers can execute arbitrary code by manipulating environment variables in Gradle start scripts, affecting developers using Unix-like systems.

Exploited in the wild
Not known
Login needed
Any signed-in user
Attackable
Over the internet
Victim action needed
Not needed
Fix
Available

What is CVE-2021-32751?

CVE-2021-32751 is a high-severity command injection vulnerability in gradle, published on 20 Jul 2021. Any signed-in user can exploit it over the network, with no action from the victim.

Official description

Gradle is a build tool with a focus on build automation. In versions prior to 7.2, start scripts generated by the `application` plugin and the `gradlew` script are both vulnerable to arbitrary code execution when an attacker is able to change environment variables for the user running the script. This may impact those who use `gradlew` on Unix-like systems or use the scripts generated by Gradle in thieir application on Unix-like systems. For this vulnerability to be exploitable, an attacker needs to be able to set the value of particular environment variables and have those environment variables be seen by the vulnerable scripts. This issue has been patched in Gradle 7.2 by removing the use of `eval` and requiring the use of the `bash` shell. There are a few workarounds available. For CI/CD systems using the Gradle build tool, one may ensure that untrusted users are unable to change environment variables for the user that executes `gradlew`. If one is unable to upgrade to Gradle 7.2, one may generate a new `gradlew` script with Gradle 7.2 and use it for older versions of Gradle. Fpplications using start scripts generated by Gradle, one may ensure that untrusted users are unable to change environment variables for the user that executes the start script. A vulnerable start script could be manually patched to remove the use of `eval` or the use of environment variables that affect the application's command-line. If the application is simple enough, one may be able to avoid the use of the start scripts by running the application directly with Java command.

Weakness: CWE-78

Which versions are affected by CVE-2021-32751?

1 open source package ship an affected version, including gradle. It affects 1 product.

PackageAffectedFixed in
gradle BitnamiAll versions7.2.0
Linux distribution packages (3)
gradle SUSE:Linux Enterprise Module for Development Tools 15 SP4All versions4.4.1-150200.3.10.1
gradle SUSE:Linux Enterprise Real Time 15 SP3All versions4.4.1-150200.3.10.1
gradle openSUSE:Leap 15.4All versions4.4.1-150200.3.10.1

Products include Gradle Gradle.

How do I fix CVE-2021-32751?

Upgrade gradle to 7.2.0 or later.

Upgrade, and pass arguments to programs as a list instead of through a shell. More about Command injection.

Is CVE-2021-32751 being exploited?

There is no known exploitation of CVE-2021-32751 in the wild and no public exploit code.

Sources

Also known as BIT-gradle-2021-32751, CLEANSTART-2026-BD83881, CLEANSTART-2026-KX40162, DEBIAN-CVE-2021-32751, GHSA-6j2p-252f-7mw8, SUSE-SU-2023:2203-1 and 1 more.

Is CVE-2021-32751 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free