Summary
A command injection vulnerability in the Bash completion script of gradle-completion (up to and including 9.3.0) allows arbitrary command execution when Bash tab completion is used in a project with a malicious Gradle build file.
Because task names and descriptions are not safely sanitized, attacker-controlled content in the Gradle build can be executed on the developer's machine during tab completion, without the user explicitly running any Gradle task.
Affected context
This vulnerability appears when developers use Bash with the gradle-completion integration enabled and work inside a Gradle project whose build scripts can be influenced by untrusted or partially trusted parties (for example, cloned example projects, training repositories, or shared internal templates).
The issue is specific to the Bash completion script: Zsh completion is not affected.
It manifests during interactive shell usage, particularly when users rely on tab completion for Gradle tasks or arguments.
Exploit preconditions
- Attack surface: Local developer shell environment (Bash) using gradle-completion.
- Required access: Ability to introduce or modify a Gradle build file in a project directory that a developer will open and use with Bash completion (e.g., via a repository, template, or shared project).
- Trigger point: The user presses tab in Bash to auto-complete a Gradle command in the affected project, causing the completion script to process task names and descriptions.
- Why exploitation is possible: The Bash completion script interpolates Gradle task names and descriptions directly into shell command contexts without proper escaping or sanitization, allowing shell metacharacters (such as backticks) to be interpreted as commands rather than plain text.
Why this happens
The core issue is unsanitized insertion of external, script-controlled data into a shell command line within the Bash completion logic.
Gradle task names and descriptions, derived from project build files, are treated as trusted text and embedded into shell command substitutions or echoed strings that the shell then evaluates.
Under CWE-78 (Improper Neutralization of Special Elements used in an OS Command), this pattern occurs when shell metacharacters (such as backticks, $(), or other control characters) are not neutralized before being processed by the interpreter.
CWE-157 is related in that completion and interactive features expose additional attack surface when they assume project metadata is benign, effectively extending the trust boundary of the developer's shell to untrusted build configuration.
Potential impact
- Execution of arbitrary shell commands on the developer's machine during tab completion.
- Installation of malware or backdoors under the developer's OS account.
- Exfiltration of local files, credentials, SSH keys, or access tokens.
- Modification of local source code or build artifacts.
- Pivoting into other internal services accessible from the developer's environment.
General mitigation guidance
Safer patterns focus on eliminating evaluation of untrusted text within shell contexts and minimizing the trust placed in build metadata:
- Ensure completion scripts treat task names and descriptions as plain data, not executable fragments, by using robust escaping and avoiding command substitution when rendering suggestions.
- Prefer APIs or helper functions that build argument lists without passing through a shell, or that avoid invoking the shell altogether where possible.
- Constrain what data from build files is surfaced into completion (for example, restrict to simple, validated identifiers rather than free-form descriptions).
- Where interactive integrations must parse project content, apply strict validation and encoding rules to neutralize shell metacharacters before use.
- Encourage developers to disable Gradle Bash completion when working with untrusted projects or repositories, especially those obtained from the internet or unknown contributors.
How teams detect issues like this
Detection generally involves reviewing shell integration code paths and how they handle external project data:
- Use static analysis or code search to identify shell scripts and completion functions that interpolate project-derived strings into
eval, command substitutions, or unquoted variable expansions. - During code review, flag any use of backticks,
$(), orevalon data that might originate from build files, environment variables, or repository contents. - Establish policies for shell integration and completion scripts that require explicit escaping functions (e.g., routines that safely quote arguments for the shell) when handling external metadata.
- Consider running automated security linters or shell script analyzers (for example, tools that warn on unsafe expansions or command injection patterns) across completion scripts and helper utilities.
- In CI for tooling repositories, include tests that simulate untrusted project metadata and confirm that completion output is safely rendered as text without being executed.

