Description
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.
Severity (CVSS)
| Base score | 8.7 |
|---|---|
| Severity | High |
| Version | CVSS 4.0 |
| Vector | CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N |
| Provided by | CNA |
Weaknesses
- CWE-94 — Improper Control of Generation of Code ('Code Injection')
Affected products
| Vendor | Product | Versions |
|---|---|---|
| oapi-codegen | oapi-codegen | 2.0.0 to <2.8.1 [affected] |
References
- https://github.com/oapi-codegen/oapi-codegen/security/advisories/GHSA-g2vv-83pm-v2hc (vendor-advisory)
- https://github.com/oapi-codegen/oapi-codegen/pull/2626 (patch issue-tracking)
- https://github.com/oapi-codegen/oapi-codegen/commit/068f1bcd16e4724c72d78d6774008a877b8297b1 (patch)
- https://github.com/oapi-codegen/oapi-codegen/blob/v2.8.0/pkg/codegen/templates/constants.tmpl#L16 (technical-description)
- https://github.com/oapi-codegen/oapi-codegen/blob/v2.0.0/pkg/codegen/templates/constants.tmpl#L12 (technical-description)
- https://github.com/oapi-codegen/oapi-codegen/releases/tag/v2.8.1 (release-notes)
- https://github.com/oapi-codegen/oapi-codegen/security/advisories/GHSA-xrqw-w576-xgj2 (related vendor-advisory)
- https://www.vulncheck.com/advisories/oapi-codegen-2.0.0-before-2.8.1-code-injection-via-non-string-enum-values (third-party-advisory)
Assess this vulnerability
Compare your deployed product and version with the source record. Review vendor references for fixes and workarounds. A CVSS score describes technical severity; it does not establish that your systems are affected or that exploitation has occurred.
Browse all CVE security advisories · Symaro cybersecurity services
Generated from the official CVE List on 30 Oct 2026 07:06 UTC.