/

CVE-2026-24905

Severity:

HIGH RISK

(7.8)

Command Injection in Inspektor Gadget Image Builder

CVE-2026-24905

Modified

Vulnerability type

Category:

Command Injection

CWE:

CWE-77, CWE-78

Impact:

Arbitrary Command Execution during Image Build

Severity:

HIGH RISK

(7.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Inspektor Gadget's ig image build command improperly interpolates user-controlled values into a Makefile template without adequate escaping, enabling command injection during image builds.

When an attacker can influence the buildOptions fields sourced from a gadget manifest, they may execute arbitrary commands on the host running ig (with --local) or inside the build container (without --local).

Affected context

This vulnerability occurs in Inspektor Gadget's image-building functionality, specifically when using the ig image build subcommand that relies on the Makefile.build template.

It is relevant in environments where:

  • The ig CLI is used to build custom gadget OCI images.
  • The buildOptions structure is populated from YAML gadget manifests (e.g., build.yml).
  • Gadgets or their manifests may originate from untrusted or semi-trusted sources, such as CI/CD pipelines that build user-submitted or third-party gadgets.

The issue is most impactful in automated build systems or shared development environments where untrusted manifests are processed without manual review.

Exploit preconditions

  • Attack surface: The ig image build command and its Makefile-based build process.
  • Required access:
  • Ability to supply or modify the gadget manifest used for building (e.g., control over build.yml or relevant options within it).
  • Practical scenarios include CI/CD jobs that automatically build gadgets based on manifests from repositories, pull requests, or external submissions.
  • Trigger point:
  • Invocation of ig image build, which:
  • Generates a Makefile from Makefile.build with embedded buildOptions values.
  • Executes Makefile targets that invoke shell commands containing these unescaped values.
  • Why exploitation is possible:
  • User-controlled data from buildOptions is inserted into shell command lines within the Makefile without proper escaping or sanitization.
  • Make invokes /bin/sh for command execution, and shell metacharacters in the unescaped data can break out of the intended argument context and inject additional commands.

Why this happens

The root cause is unsafe construction of shell-executed command lines from user-controlled input, leading to CWE-78: Improper Neutralization of Special Elements used in an OS Command (OS Command Injection).

Within inspektor-gadget/cmd/common/image/build.go, values from the buildOptions structure are embedded into the Makefile.build template. These values are ultimately passed to the shell via Makefile rules without:

  • Proper quoting or escaping suited for the target shell, or
  • A separation between data and command logic (e.g., using structured APIs instead of raw command strings).

Conceptually, this reflects a common bug pattern:

  • Treating configuration values as "safe" and interpolating them into executable command strings.
  • Relying on Makefile and shell behavior where special characters (;, &, |, backticks, $(), etc.) are interpreted as control or substitution operators.

The combination of template-based command generation and inadequate neutralization of shell metacharacters allows attackers to craft buildOptions values that alter the intended command sequence and execute arbitrary OS commands during the build process.

Potential impact

  • Execution of arbitrary OS commands on the Linux host where ig is run when using the --local flag.
  • Execution of arbitrary OS commands within the build container environment when --local is not used.
  • Compromise of CI/CD runners or build agents, potentially leading to broader infrastructure access.
  • Insertion of backdoors, malicious tooling, or data exfiltration logic into built gadget images.
  • Lateral movement opportunities if the compromised host or container has access to Kubernetes clusters, registries, or other internal systems.

General mitigation guidance

Mitigation should focus on eliminating direct command-string construction from untrusted data and ensuring shell interaction is strictly controlled.

Recommended defensive patterns include:

  • Avoid shell-based templating when possible:
  • Prefer programmatic build APIs or libraries that accept arguments as structured lists instead of concatenated command strings.
  • Apply strict escaping and quoting:
  • When shell execution is unavoidable, apply context-aware escaping to all user-controlled values before inserting them into Makefiles or shell commands.
  • Use robust quoting strategies (e.g., single-quoting data segments and carefully handling embedded quotes) appropriate for /bin/sh.
  • Constrain the configuration surface:
  • Restrict which buildOptions fields can influence commands; prefer enumerated options or whitelists over free-form strings.
  • Validate manifest fields against schemas that limit the presence of shell metacharacters where they are not necessary.
  • Isolate and harden the build environment:
  • Run ig image build in locked-down, ephemeral build environments with minimal privileges and restricted network/file-system access.
  • Apply least-privilege principles to the build user and any helper tools.
  • Treat manifests as untrusted input:
  • Even internally generated manifests should undergo validation and sanitization before being used in command construction.

How teams detect issues like this

Detection can combine code-level review with runtime monitoring:

  • Static analysis and code review:
  • Search for patterns where user-controlled fields (e.g., from buildOptions, YAML manifests, or CLI flags) are directly concatenated into Makefile templates or shell commands.
  • Flag uses of fmt.Sprintf, string templates, or text replacement functions that populate Makefile rules with unescaped values.
  • Establish review checklists for:
  • Any new Makefile templates that embed dynamic values.
  • Any code that executes make, sh, or other command interpreters with arguments built from configuration data.
  • Policy-based checks in CI:
  • Enforce linting rules that disallow unsafe shell command construction and encourage structured argument passing.
  • Use configuration-as-code scanning tools to detect suspicious shell expansions within templates and build scripts.
  • Runtime monitoring:
  • Log and review commands executed by build pipelines, especially those originating from ig image build.
  • Monitor for unexpected child processes, network connections, or filesystem modifications during gadget image builds, which may indicate exploitation attempts.

Sources

SourceLink
github.comgithub.com/inspektor-gadget/inspektor-gadget/commit/7c83ad84ff7a68565655253e2cf1c5d2da695c1a
github.comgithub.com/inspektor-gadget/inspektor-gadget/commit/d9bf2fe4a180dad33ce57ca793ff4799ee7b8320
github.comgithub.com/inspektor-gadget/inspektor-gadget/security/advisories/GHSA-79qw-g77v-2vfh

Frequently asked

questions

Exploitability is significant in environments where untrusted or partially trusted gadget manifests are built automatically, such as CI/CD pipelines. If an attacker can control the buildOptions in the manifest, they can often craft values that trigger command injection during the build process.

The attacker must be able to influence the gadget manifest used with ig image build, either by supplying a full build.yml file or modifying specific options that map into buildOptions. In many setups, this corresponds to the ability to submit or modify gadget source or configuration in a repository processed by automated builds.

The most robust fix is to avoid interpolating configuration values into shell commands altogether. Instead, use APIs that construct commands from argument arrays or otherwise separate data from command syntax. If templating is unavoidable, apply strict, context-aware escaping for all user-controlled fields and constrain those fields to safe, validated values.

Prevention relies on designing build and automation tools with untrusted input in mind:

  • Treat all configuration, manifests, and CLI input as untrusted.
  • Avoid shell-based composition where data is mixed with control syntax.
  • Enforce schema validation, whitelists, and normalization for configuration fields.
  • Integrate security reviews and automated checks specifically targeting injection risks into the development and CI processes before new build paths are adopted.
Find out what's already
exploitable in your codebase.