/

CVE-2026-48054

Severity:

HIGH RISK

(8.8)

Code Injection (CWE-94) in OpenZeppelin Contracts Wizard

CVE-2026-48054

Received

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution

Severity:

HIGH RISK

(8.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

OpenZeppelin Contracts Wizard generated Hardhat test files by inserting user-controlled contract names or URIs directly into TypeScript string literals without escaping them. An attacker could craft a malicious Wizard URL and share it with a developer, causing code to execute with the developer's local OS privileges when the generated project tests are run.

Affected context

The vulnerability occurs in the Wizard's Hardhat project generation workflow when user-supplied ERC20, ERC721, or ERC1155 metadata is copied into the generated test/test.ts file. Deployments or workflows that allow developers to download and execute generated projects may be at risk, particularly when shared Wizard links are treated as trusted and the generated tests are run locally.

Exploit preconditions

  • Attack surface: OpenZeppelin Contracts Wizard URL parameters and generated Hardhat project archives
  • Required access: No authentication is required; the attacker needs to provide or share a crafted Wizard link
  • Victim action: A developer downloads the generated archive and runs the project's Hardhat tests
  • Trigger point: Interpolation of attacker-controlled name or uri values into TypeScript string literals
  • Why exploitation is possible: Generated source code does not apply JavaScript or TypeScript string escaping before incorporating user-controlled values

Why this happens

The underlying bug is direct interpolation of untrusted input into generated source code without context-appropriate escaping. Values intended to remain data are placed inside TypeScript string literals, allowing specially constructed input to alter the surrounding program structure when the generated file is later interpreted.

This behavior maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), because attacker-controlled data becomes executable code in a generated artifact. The risk is amplified by treating generated test files as trusted code and executing them with the developer's local privileges.

Potential impact

  • Arbitrary Node.js or operating system command execution on the developer's machine
  • Theft or modification of local files, credentials, and source code
  • Compromise of development tools, wallets, or environment secrets
  • Tampering with generated contracts, tests, or build artifacts
  • Further compromise of connected repositories or deployment environments

General mitigation guidance

Mitigation generally focuses on keeping user-controlled values as data rather than source code.

Common defensive patterns include:

  • Apply context-appropriate JavaScript or TypeScript string escaping before generating source files
  • Prefer structured data files, parameterized templates, or safe serialization over source-code interpolation
  • Validate generated artifacts against an expected schema and reject unexpected syntax
  • Treat shared generator URLs and downloaded archives as untrusted input
  • Run generated tests in isolated, least-privileged environments with restricted filesystem and network access
  • Avoid exposing developer credentials and production secrets to build or test processes

How teams detect issues like this

Organizations can look for:

  • Static analysis findings where request parameters or template values are concatenated into JavaScript or TypeScript source
  • Code review signals involving template interpolation inside quoted literals
  • Tests using quote, escape, newline, and delimiter characters to verify generated files remain syntactically and semantically data-only
  • Artifact scanning that parses generated test files and compares them with an expected template structure
  • CI policies requiring context-aware output encoding for code generators
  • Automated security review tools that flag unescaped input reaching source-code generation sinks

Sources

SourceLink
github.comgithub.com/OpenZeppelin/contracts-wizard/commit/ec12c44f8d9e0491eba31037f95b36e98ec58b5f
github.comgithub.com/OpenZeppelin/contracts-wizard/releases/tag/%40openzeppelin%2Fwizard%400.10.9
github.comgithub.com/OpenZeppelin/contracts-wizard/security/advisories/GHSA-4x76-22x2-rx8v

Frequently asked

questions

The attacker does not need direct access to the victim's machine or authentication to the Wizard. However, exploitation depends on a victim opening a crafted link, downloading the generated project, and running its tests.

The attacker only needs to create and share a maliciously constructed Wizard URL. The victim's local execution of the generated test file provides the execution context.

Treat all Wizard inputs as untrusted data, use safe serialization or context-aware escaping during code generation, and validate generated artifacts before execution.

Add code-generation security tests, review every path from user input to generated source, scan templates for unsafe interpolation, and run generated projects with least privilege and isolation.

Find out what's already
exploitable in your codebase.