oapi-codegen: Code injection via non-string enum values in OpenAPI specs
Summary
oapi-codegen versions 2.0.0 up to 2.8.0 allow code injection through non-literal enum entries in integer, number or boolean schemas of an OpenAPI document. An attacker who controls the OpenAPI document can craft an enum entry that closes the const block in the code template and inserts a func init() function. The injected code runs when the generated package is built and imported, typically on developer machines or CI runners. The NVD rating (CVSS 4.0 8.7) assumes that a user must process the malicious document (UI:P).
Affected
- oapi-codegen 2.0.0 up to but not including 2.8.1
- Packages in downstream distributions may still ship older versions (for example Nixpkgs release-26.05 at 2.5.1, which is in the affected range)
Fixed in
- Version 2.8.1 (vendor advisory GHSA-g2vv-83pm-v2hc)
Workaround
- No vendor-published workaround specific to this CVE. Unknown.
- Only generate code from OpenAPI specifications you control or have reviewed.
- Download remote specifications locally and validate them before running oapi-codegen. This reduces exposure but is not a fix.
- Pin the generator version and do not run code generation on untrusted input in CI pipelines that have access to secrets.
Exploitation
- No public exploit confirmed. VulDB states that no exploit is available.
- No evidence of exploitation in the wild found.
- Unconfirmed: an OffSeq page mentions Metasploit and nuclei content, but this is not clearly linked to this CVE.
- CISA SSVC: exploitation none, automatable no, technical impact total.
Our recommendation
- Upgrade oapi-codegen to version 2.8.1 or later, including in CI images and developer toolchains.
- Check that generated code and the github.com/oapi-codegen/runtime version are compatible with the new release before upgrading.
- Review which OpenAPI specifications are processed, especially third-party or remotely fetched ones, and validate them before code generation.
- Check distribution packages for older versions and update them separately.
- Priority: moderate for teams that generate code from external specifications, low for teams that only use their own specifications.
Public exploits
PoC-in-GitHub, Metasploit and Exploit-DB list nothing for this CVE.
Research sources
- GitHub Security Advisory GHSA-g2vv-83pm-v2hc github.com
- oapi-codegen v2.8.1 release github.com
- Fix commit 068f1bc github.com
- Patch pull request #2626 github.com
- VulnCheck advisory www.vulncheck.com
- Nixpkgs issue on release-26.05 lag github.com
- VulDB entry vuldb.com
Researched and written up in English and German by an AI (Claude by Anthropic) based on NVD, CISA, EPSS and the sources listed. The vendor information is authoritative. Researched on 31 Oct 2026, 23:42.
Original description (NVD)
oapi-codegen 2.0.0 before 2.8.1 contains a code injection vulnerability that allows attackers to inject Go code by supplying non-literal enum entries in integer, number, or boolean schemas. Attackers controlling an OpenAPI document can craft an enum entry that closes the const block in constants.tmpl and injects a func init(), executing code when the generated package is built and imported.
NVD references (8)
- https://github.com/oapi-codegen/oapi-codegen/blob/v2.0.0/pkg/codegen/templates/constants.tmpl#L12
- https://github.com/oapi-codegen/oapi-codegen/blob/v2.8.0/pkg/codegen/templates/constants.tmpl#L16
- https://github.com/oapi-codegen/oapi-codegen/commit/068f1bcd16e4724c72d78d6774008a877b8297b1
- https://github.com/oapi-codegen/oapi-codegen/pull/2626
- https://github.com/oapi-codegen/oapi-codegen/releases/tag/v2.8.1
- https://github.com/oapi-codegen/oapi-codegen/security/advisories/GHSA-g2vv-83pm-v2hc
- https://github.com/oapi-codegen/oapi-codegen/security/advisories/GHSA-xrqw-w576-xgj2
- https://www.vulncheck.com/advisories/oapi-codegen-2.0.0-before-2.8.1-code-injection-via-non-string-enum-values
Sources
The tracker combines official, freely usable data sources – updated continuously:
- NVD (NIST) – CVEs, rating (CVSS), affected products
- CISA KEV – vulnerabilities confirmed by CISA as actively exploited
- CISA Vulnrichment – CISA assessment (SSVC) in the official CVE record
- FIRST EPSS – probability of exploitation
- Microsoft MSRC – Patch Tuesday: vulnerabilities, severity, updates
- PoC-in-GitHub – public proof-of-concept repositories
- Metasploit (Rapid7) – modules of the Metasploit Framework
- Exploit-DB (OffSec) – archive of public exploits (links only)
- Patch days: official vendor pages (linked per vendor) (Vendor patch days)
This product uses data from the NVD API but is not endorsed or certified by the NVD. EPSS data © FIRST.org.
Affected? We can help.
We check whether your systems are affected, install updates and close the gap – continuously with the System Health Checker if you wish.
