Summary
Melange pipelines from versions 0.3.0 to before 0.40.3 embed user-supplied values into shell scripts without proper quoting when used in the working-directory field with ${{vars.*}} or ${{inputs.*}} substitutions.
An attacker who can control these build input values, even without modifying the pipeline definition itself, may execute arbitrary shell commands during the build process.
Affected context
This vulnerability appears in Melange declarative pipelines where:
- The
working-directoryfield is set dynamically using${{vars.*}}or${{inputs.*}}substitutions - Build inputs or variables can be influenced by less-trusted users or external automation
- The effective value is later interpolated into shell scripts that are executed as part of the build
The risk is present in CI/CD or build environments where Melange runs with elevated privileges, access to secrets, or access to internal package repositories.
Exploit preconditions
- Attack surface: Melange build configuration and any interface that supplies pipeline variables or build inputs (e.g., CI parameters, config files, API calls).
- Required access: Ability to control the values of
vars.*orinputs.*referenced in theworking-directoryfield; no need to change the pipeline YAML itself. - Trigger point: Execution of the build pipeline step that generates and runs shell scripts using the unescaped
working-directoryvalue. - Why exploitation is possible: The
working-directoryvalue is interpolated directly into shell command contexts without appropriate quoting or escaping, allowing crafted values to break out of the intended path and inject additional shell syntax.
Why this happens
The core issue maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
Melange treats working-directory as a simple string but later embeds it directly into shell scripts without enforcing safe quoting. When ${{vars.*}} or ${{inputs.*}} substitutions are used, untrusted data flows into a command line context where shell metacharacters (e.g., ;, &&, |, backticks, or $()) are interpreted as control operators.
This design implicitly assumes that substituted values are safe file system paths, but it does not enforce or encode that assumption, allowing an attacker-controlled value to modify the structure of the executed command instead of just its argument.
Potential impact
- Execution of arbitrary shell commands during the build process
- Compromise of the build agent or CI worker environment
- Theft or exposure of build-time secrets, credentials, and signing keys
- Manipulation or backdooring of built APK packages
- Lateral movement within the CI/CD or build infrastructure
General mitigation guidance
Effective mitigation focuses on treating all substituted values as untrusted and ensuring they cannot alter shell command structure:
- Use APIs or execution models that avoid constructing shell command strings; prefer direct process invocation with argument arrays where possible.
- Apply strict quoting and escaping to any variable interpolated into shell commands, especially path-like fields such as
working-directory. - Constrain
working-directoryto validated, whitelist-based path patterns (e.g., alphanumeric,_,-,/) and reject values containing shell metacharacters. - Separate configuration privileges so that untrusted parties cannot provide values for fields that end up in execution-critical contexts.
- Run build jobs with least privilege, minimizing access to secrets and sensitive file system locations so that impact is limited even if injection occurs.
How teams detect issues like this
Organizations can detect and manage this class of issue through:
- Static analysis of pipeline definitions: Flagging uses of
${{vars.*}}or${{inputs.*}}in execution-related fields (likeworking-directory) that are later passed to shell commands without a clear quoting strategy. - Pattern-based scanning: Searching for command templates or script fragments that concatenate user-controlled values into shell strings instead of passing them as separate arguments.
- Code review checklists: Ensuring reviewers specifically verify how Melange variables and inputs are consumed when they influence paths, commands, or environment variables.
- Policy enforcement in CI: Adding automated checks in CI to block pipelines that interpolate untrusted inputs directly into shell execution contexts.

