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
nameorurivalues 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

