/

CVE-2026-42301

Severity:

HIGH RISK

(7.8)

Code Injection via Unvalidated Input in pyp2spec RPM Spec

CVE-2026-42301

Deferred

Vulnerability type

Category:

Code Injection via Unvalidated Input

CWE:

CWE-20, CWE-94

Impact:

Arbitrary Code Execution on Build Infrastructure

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

pyp2spec previously wrote unescaped PyPI package metadata directly into generated Fedora RPM spec files, allowing embedded RPM macro directives to be interpreted during build.

If a malicious Python package includes crafted metadata fields, this behavior can lead to arbitrary command execution on the build machine when rpmbuild processes the spec file.

Affected context

This vulnerability appears in environments where:

  • pyp2spec is used to auto-generate Fedora RPM spec files from PyPI metadata.
  • Packagers or automated pipelines consume PyPI packages that may not be fully trusted.
  • The generated spec files are passed directly to rpmbuild without sanitizing or escaping RPM macro directives.

The problematic behavior is tied to textual metadata fields such as the package summary or description, which can embed RPM macros that are later evaluated during the build process.

Exploit preconditions

  • Attack surface: Supply chain via PyPI package metadata consumed by pyp2spec.
  • Required access: Ability to publish or control a Python package whose metadata will be processed by pyp2spec.
  • Trigger point: Running pyp2spec to generate a spec file and subsequently invoking rpmbuild on that spec.
  • Why exploitation is possible: pyp2spec treated metadata as benign text and inserted it into spec files without escaping RPM macro syntax, allowing macros to be interpreted as build-time commands.

Why this happens

The core issue is unvalidated and unescaped propagation of external input (PyPI metadata) into a command-evaluated context (RPM spec files).

This maps to CWE-20: Improper Input Validation because the tool trusted package metadata without constraining or validating characters and patterns meaningful to RPM macros.

It also aligns with CWE-94: Improper Control of Generation of Code ('Code Injection') since the untrusted metadata can be crafted to introduce macro-based commands that rpmbuild interprets, effectively injecting executable logic into the build process. The insecure pattern is treating descriptive metadata as inherently safe, even when it is fed into a domain-specific language that supports command execution.

Potential impact

  • Malicious packages may cause arbitrary shell commands to execute during RPM build.
  • Compromise of build machines, including theft of secrets or credentials present in the build environment.
  • Tampering with built RPM artifacts, enabling downstream supply-chain attacks on users of the packages.
  • Disruption of CI/CD pipelines and potential lateral movement within build infrastructure.

General mitigation guidance

Mitigation typically involves treating all external metadata as untrusted and constraining how it flows into build definitions.

Useful defensive patterns include:

  • Escaping or neutralizing RPM macro syntax in all user- or package-supplied text before inserting it into spec files.
  • Applying strict input validation and whitelisting for fields that are rendered into build scripts or specification languages.
  • Separating build logic from descriptive metadata, ensuring that text fields cannot influence command execution.
  • Running build processes under least-privilege accounts and isolating build environments to reduce impact if a build step is compromised.

How teams detect issues like this

Detection can focus on both source code and build artifacts:

  • Static analysis and code review: Look for tools that copy external metadata directly into build specs or scripts without escaping or validation, especially where domain-specific macro languages are involved.
  • Policy checks in CI: Enforce rules that scan generated spec files for unexpected or untrusted RPM macros originating from package metadata.
  • Logging and monitoring: Capture and review rpmbuild logs for unusual macro expansions or unexpected command invocations during builds.
  • Automated tooling: Use security linters or SAST tools configured to flag patterns where user-controlled strings are embedded into DSLs or configuration files that support evaluation.

Sources

SourceLink
github.comgithub.com/befeleme/pyp2spec/releases/tag/v0.14.1
github.comgithub.com/befeleme/pyp2spec/security/advisories/GHSA-r35x-v8p8-xvhw

Frequently asked

questions

It can be exploited remotely in a supply-chain sense: an attacker only needs to publish or control a malicious Python package that is later processed by pyp2spec and built by a packager or automated pipeline.

The attacker must be able to influence the package metadata consumed by pyp2spec—typically by maintaining or compromising a package that will be converted into an RPM spec and built with rpmbuild.

The safest pattern is to ensure all untrusted metadata is sanitized and escaped before being embedded in spec files, eliminating or neutralizing RPM macro syntax so that descriptive fields cannot be interpreted as commands during the build.

Treat all external data, including package metadata, as untrusted; apply strict input validation and encoding when such data is fed into build specifications or scripts; and integrate security checks into the tooling and CI pipeline to detect unsafe propagation of user-controlled input into executable or macro-enabled contexts.

Find out what's already
exploitable in your codebase.