CWE-94
Allowed-with-ReviewImproper Control of Generation of Code ('Code Injection')
Abstraction: Base · Status: Draft
The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
8376 vulnerabilities reference this CWE, most recent first.
GHSA-4RCH-2FH8-94VW
Vulnerability from github – Published: 2024-04-23 06:30 – Updated: 2024-04-23 20:50Versions of the package mysql2 before 3.9.7 are vulnerable to Arbitrary Code Injection due to improper sanitization of the timezone parameter in the readCodeFor function by calling a native MySQL Server date/time function.
{
"affected": [
{
"package": {
"ecosystem": "npm",
"name": "mysql2"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "3.9.7"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2024-21511"
],
"database_specific": {
"cwe_ids": [
"CWE-94"
],
"github_reviewed": true,
"github_reviewed_at": "2024-04-23T20:50:56Z",
"nvd_published_at": "2024-04-23T05:15:48Z",
"severity": "CRITICAL"
},
"details": "Versions of the package mysql2 before 3.9.7 are vulnerable to Arbitrary Code Injection due to improper sanitization of the timezone parameter in the readCodeFor function by calling a native MySQL Server date/time function.",
"id": "GHSA-4rch-2fh8-94vw",
"modified": "2024-04-23T20:50:56Z",
"published": "2024-04-23T06:30:47Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2024-21511"
},
{
"type": "WEB",
"url": "https://github.com/sidorares/node-mysql2/pull/2608"
},
{
"type": "WEB",
"url": "https://github.com/sidorares/node-mysql2/commit/7d4b098c7e29d5a6cb9eac2633bfcc2f0f1db713"
},
{
"type": "PACKAGE",
"url": "https://github.com/sidorares/node-mysql2"
},
{
"type": "WEB",
"url": "https://github.com/sidorares/node-mysql2/releases/tag/v3.9.7"
},
{
"type": "WEB",
"url": "https://security.snyk.io/vuln/SNYK-JS-MYSQL2-6670046"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H",
"type": "CVSS_V3"
}
],
"summary": "MySQL2 for Node Arbitrary Code Injection"
}
GHSA-4RG2-XC78-49M2
Vulnerability from github – Published: 2022-05-01 18:29 – Updated: 2025-04-09 03:46Multiple PHP remote file inclusion vulnerabilities in pSlash 0.70 allow remote attackers to execute arbitrary PHP code via a URL in (1) the lvc_admin_dir parameter to modules/visitors2/admin/view-archiver.inc.php or (2) the lvc_include_dir parameter to modules/visitors2/include/menus.inc.php. NOTE: the modules/visitors2/include/config.inc.php vector is already covered by CVE-2006-4373. NOTE: vector 1 is disputed by CVE because PHP encounters a fatal instantiation error on a direct request for the file, before reaching the include statement.
{
"affected": [],
"aliases": [
"CVE-2007-5014"
],
"database_specific": {
"cwe_ids": [
"CWE-94"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2007-09-20T21:17:00Z",
"severity": "HIGH"
},
"details": "Multiple PHP remote file inclusion vulnerabilities in pSlash 0.70 allow remote attackers to execute arbitrary PHP code via a URL in (1) the lvc_admin_dir parameter to modules/visitors2/admin/view-archiver.inc.php or (2) the lvc_include_dir parameter to modules/visitors2/include/menus.inc.php. NOTE: the modules/visitors2/include/config.inc.php vector is already covered by CVE-2006-4373. NOTE: vector 1 is disputed by CVE because PHP encounters a fatal instantiation error on a direct request for the file, before reaching the include statement.",
"id": "GHSA-4rg2-xc78-49m2",
"modified": "2025-04-09T03:46:26Z",
"published": "2022-05-01T18:29:21Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2007-5014"
},
{
"type": "WEB",
"url": "http://arfis.wordpress.com/2007/09/14/rfi-03-pslash"
},
{
"type": "WEB",
"url": "http://osvdb.org/38288"
},
{
"type": "WEB",
"url": "http://osvdb.org/38289"
}
],
"schema_version": "1.4.0",
"severity": []
}
GHSA-4RJP-9XF6-39JC
Vulnerability from github – Published: 2022-05-01 18:35 – Updated: 2022-05-01 18:35Multiple PHP remote file inclusion vulnerabilities in PeopleAggregator 1.2pre6, when register_globals is enabled, allow remote attackers to execute arbitrary PHP code via a URL in the current_blockmodule_path parameter to (1) AudiosMediaGalleryModule/AudiosMediaGalleryModule.php, (2) ImagesMediaGalleryModule/ImagesMediaGalleryModule.php, (3) MembersFacewallModule/MembersFacewallModule.php, (4) NewestGroupsModule/NewestGroupsModule.php, (5) UploadMediaModule/UploadMediaModule.php, and (6) VideosMediaGalleryModule/VideosMediaGalleryModule.php in BetaBlockModules/; and (7) the path_prefix parameter to several components.
{
"affected": [],
"aliases": [
"CVE-2007-5631"
],
"database_specific": {
"cwe_ids": [
"CWE-94"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2007-10-23T17:46:00Z",
"severity": "MODERATE"
},
"details": "Multiple PHP remote file inclusion vulnerabilities in PeopleAggregator 1.2pre6, when register_globals is enabled, allow remote attackers to execute arbitrary PHP code via a URL in the current_blockmodule_path parameter to (1) AudiosMediaGalleryModule/AudiosMediaGalleryModule.php, (2) ImagesMediaGalleryModule/ImagesMediaGalleryModule.php, (3) MembersFacewallModule/MembersFacewallModule.php, (4) NewestGroupsModule/NewestGroupsModule.php, (5) UploadMediaModule/UploadMediaModule.php, and (6) VideosMediaGalleryModule/VideosMediaGalleryModule.php in BetaBlockModules/; and (7) the path_prefix parameter to several components.",
"id": "GHSA-4rjp-9xf6-39jc",
"modified": "2022-05-01T18:35:20Z",
"published": "2022-05-01T18:35:20Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2007-5631"
},
{
"type": "WEB",
"url": "https://exchange.xforce.ibmcloud.com/vulnerabilities/37349"
},
{
"type": "WEB",
"url": "https://www.exploit-db.com/exploits/4551"
},
{
"type": "WEB",
"url": "http://osvdb.org/45495"
},
{
"type": "WEB",
"url": "http://osvdb.org/45496"
},
{
"type": "WEB",
"url": "http://osvdb.org/45497"
},
{
"type": "WEB",
"url": "http://osvdb.org/45498"
},
{
"type": "WEB",
"url": "http://osvdb.org/45499"
},
{
"type": "WEB",
"url": "http://osvdb.org/45500"
},
{
"type": "WEB",
"url": "http://osvdb.org/45501"
},
{
"type": "WEB",
"url": "http://www.myelin.co.nz/post/2007/11/12/#200711121"
},
{
"type": "WEB",
"url": "http://www.securityfocus.com/archive/1/483571/100/0/threaded"
},
{
"type": "WEB",
"url": "http://www.securityfocus.com/bid/26147"
}
],
"schema_version": "1.4.0",
"severity": []
}
GHSA-4RM2-28VJ-FJ39
Vulnerability from github – Published: 2026-05-06 19:54 – Updated: 2026-05-13 16:41Impact
A remote code execution (RCE) vulnerability affects versions 0.13.2 through 0.13.21. When documentation endpoints are publicly accessible and validation rules reference user-controlled input, request supplied data may be evaluated during documentation generation, leading to execution of arbitrary PHP code in the application context.
Patches
Fixed in version 0.13.22.
Workarounds
If upgrading is not immediately possible:
- Restrict access to documentation endpoints (
/docs/api,/docs/api.json) - Avoid using user-controlled variables inside validation rule expressions (e.g., values derived from request input)
- Disable documentation endpoints in production environments if not required
These measures significantly reduce or prevent exploitability.
{
"affected": [
{
"database_specific": {
"last_known_affected_version_range": "\u003c= 0.13.21"
},
"package": {
"ecosystem": "Packagist",
"name": "dedoc/scramble"
},
"ranges": [
{
"events": [
{
"introduced": "0.13.2"
},
{
"fixed": "0.13.22"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2026-44262"
],
"database_specific": {
"cwe_ids": [
"CWE-94"
],
"github_reviewed": true,
"github_reviewed_at": "2026-05-06T19:54:56Z",
"nvd_published_at": "2026-05-12T22:16:36Z",
"severity": "CRITICAL"
},
"details": "### Impact\n\nA remote code execution (RCE) vulnerability affects versions `0.13.2` through `0.13.21`. When documentation endpoints are publicly accessible and validation rules reference user-controlled input, request supplied data may be evaluated during documentation generation, leading to execution of arbitrary PHP code in the application context.\n\n### Patches\n\nFixed in version `0.13.22`.\n\n### Workarounds\n\nIf upgrading is not immediately possible:\n\n* Restrict access to documentation endpoints (`/docs/api`, `/docs/api.json`)\n* Avoid using user-controlled variables inside validation rule expressions (e.g., values derived from request input)\n* Disable documentation endpoints in production environments if not required\n\nThese measures significantly reduce or prevent exploitability.",
"id": "GHSA-4rm2-28vj-fj39",
"modified": "2026-05-13T16:41:47Z",
"published": "2026-05-06T19:54:56Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/dedoc/scramble/security/advisories/GHSA-4rm2-28vj-fj39"
},
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2026-44262"
},
{
"type": "PACKAGE",
"url": "https://github.com/dedoc/scramble"
},
{
"type": "WEB",
"url": "https://github.com/dedoc/scramble/releases/tag/v0.13.22"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:L",
"type": "CVSS_V3"
}
],
"summary": "Scramble vulnerable to remote code execution via evaluation of user-controlled input in validation rules"
}
GHSA-4RMG-292M-WG3W
Vulnerability from github – Published: 2024-05-29 18:44 – Updated: 2025-11-04 16:50Impact
Template authors could inject php code by choosing a malicous file name for an extends-tag. Users that cannot fully trust template authors should update asap.
Patches
Please upgrade to the most recent version of Smarty v4 or v5. There is no patch for v3.
{
"affected": [
{
"package": {
"ecosystem": "Packagist",
"name": "smarty/smarty"
},
"ranges": [
{
"events": [
{
"introduced": "5.0.0"
},
{
"fixed": "5.1.1"
}
],
"type": "ECOSYSTEM"
}
]
},
{
"package": {
"ecosystem": "Packagist",
"name": "smarty/smarty"
},
"ranges": [
{
"events": [
{
"introduced": "3.0.0"
},
{
"fixed": "4.5.3"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2024-35226"
],
"database_specific": {
"cwe_ids": [
"CWE-94"
],
"github_reviewed": true,
"github_reviewed_at": "2024-05-29T18:44:30Z",
"nvd_published_at": "2024-05-28T21:16:30Z",
"severity": "HIGH"
},
"details": "### Impact\nTemplate authors could inject php code by choosing a malicous file name for an extends-tag. Users that cannot fully trust template authors should update asap.\n\n### Patches\nPlease upgrade to the most recent version of Smarty v4 or v5. There is no patch for v3.",
"id": "GHSA-4rmg-292m-wg3w",
"modified": "2025-11-04T16:50:38Z",
"published": "2024-05-29T18:44:30Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/smarty-php/smarty/security/advisories/GHSA-4rmg-292m-wg3w"
},
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2024-35226"
},
{
"type": "WEB",
"url": "https://github.com/smarty-php/smarty/commit/0be92bc8a6fb83e6e0d883946f7e7c09ba4e857a"
},
{
"type": "PACKAGE",
"url": "https://github.com/smarty-php/smarty"
},
{
"type": "WEB",
"url": "https://lists.debian.org/debian-lts-announce/2024/11/msg00013.html"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:N",
"type": "CVSS_V3"
}
],
"summary": "Smarty vulnerable to PHP Code Injection by malicious attribute in extends-tag"
}
GHSA-4RMR-C2JX-VX27
Vulnerability from github – Published: 2022-01-27 14:51 – Updated: 2022-08-11 17:05In Mustache.php v2.0.0 through v2.14.0, Sections tag can lead to arbitrary php code execution even if strict_callables is true when section value is controllable.
{
"affected": [
{
"package": {
"ecosystem": "Packagist",
"name": "mustache/mustache"
},
"ranges": [
{
"events": [
{
"introduced": "2.0.0"
},
{
"fixed": "2.14.1"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2022-0323"
],
"database_specific": {
"cwe_ids": [
"CWE-1336",
"CWE-94"
],
"github_reviewed": true,
"github_reviewed_at": "2022-01-24T23:01:39Z",
"nvd_published_at": "2022-01-21T18:15:00Z",
"severity": "HIGH"
},
"details": "In Mustache.php v2.0.0 through v2.14.0, Sections tag can lead to arbitrary php code execution even if strict_callables is true when section value is controllable.\n\n",
"id": "GHSA-4rmr-c2jx-vx27",
"modified": "2022-08-11T17:05:16Z",
"published": "2022-01-27T14:51:00Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2022-0323"
},
{
"type": "WEB",
"url": "https://github.com/bobthecow/mustache.php/commit/579ffa5c96e1d292c060b3dd62811ff01ad8c24e"
},
{
"type": "WEB",
"url": "https://github.com/FriendsOfPHP/security-advisories/blob/master/mustache/mustache/CVE-2022-0323.yaml"
},
{
"type": "PACKAGE",
"url": "https://github.com/bobthecow/mustache.php"
},
{
"type": "WEB",
"url": "https://github.com/bobthecow/mustache.php/releases/tag/v2.14.1"
},
{
"type": "WEB",
"url": "https://huntr.dev/bounties/a5f5a988-aa52-4443-839d-299a63f44fb7"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H",
"type": "CVSS_V3"
}
],
"summary": "Mustache remote code injection vulnerability"
}
GHSA-4RWX-V4CH-C62R
Vulnerability from github – Published: 2022-05-14 03:18 – Updated: 2022-05-14 03:18A Code Injection issue was discovered in DlgSelectMibFile.asp in Ipswitch WhatsUp Gold before 2018 (18.0). Malicious actors can inject a specially crafted SNMP MIB file that could allow them to execute arbitrary commands and code on the WhatsUp Gold server.
{
"affected": [],
"aliases": [
"CVE-2018-8938"
],
"database_specific": {
"cwe_ids": [
"CWE-94"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2018-05-01T16:29:00Z",
"severity": "CRITICAL"
},
"details": "A Code Injection issue was discovered in DlgSelectMibFile.asp in Ipswitch WhatsUp Gold before 2018 (18.0). Malicious actors can inject a specially crafted SNMP MIB file that could allow them to execute arbitrary commands and code on the WhatsUp Gold server.",
"id": "GHSA-4rwx-v4ch-c62r",
"modified": "2022-05-14T03:18:59Z",
"published": "2022-05-14T03:18:59Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2018-8938"
},
{
"type": "WEB",
"url": "https://docs.ipswitch.com/NM/WhatsUpGold2018/01_ReleaseNotes/index.htm"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H",
"type": "CVSS_V3"
}
]
}
GHSA-4RXR-G7CG-RWG8
Vulnerability from github – Published: 2024-06-04 15:30 – Updated: 2024-06-04 15:30Improper Control of Generation of Code ('Code Injection') vulnerability in Codeer Limited Bricks Builder allows Code Injection.This issue affects Bricks Builder: from n/a through 1.9.6.
{
"affected": [],
"aliases": [
"CVE-2024-25600"
],
"database_specific": {
"cwe_ids": [
"CWE-94"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2024-06-04T13:15:51Z",
"severity": "CRITICAL"
},
"details": "Improper Control of Generation of Code (\u0027Code Injection\u0027) vulnerability in Codeer Limited Bricks Builder allows Code Injection.This issue affects Bricks Builder: from n/a through 1.9.6.",
"id": "GHSA-4rxr-g7cg-rwg8",
"modified": "2024-06-04T15:30:58Z",
"published": "2024-06-04T15:30:58Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2024-25600"
},
{
"type": "WEB",
"url": "https://github.com/Chocapikk/CVE-2024-25600"
},
{
"type": "WEB",
"url": "https://github.com/K3ysTr0K3R/CVE-2024-25600-EXPLOIT"
},
{
"type": "WEB",
"url": "https://patchstack.com/articles/critical-rce-patched-in-bricks-builder-theme?_s_id=cve"
},
{
"type": "WEB",
"url": "https://patchstack.com/database/vulnerability/bricks/wordpress-bricks-theme-1-9-6-unauthenticated-remote-code-execution-rce-vulnerability?_s_id=cve"
},
{
"type": "WEB",
"url": "https://snicco.io/vulnerability-disclosure/bricks/unauthenticated-rce-in-bricks-1-9-6"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H",
"type": "CVSS_V3"
}
]
}
GHSA-4V3R-HQR9-69JF
Vulnerability from github – Published: 2022-06-13 00:00 – Updated: 2024-09-26 14:40Nuitka 0.8.4 and prior is vulnerable to command injection. A patch is available and anticipated to be part of the 0.9 release.
{
"affected": [
{
"database_specific": {
"last_known_affected_version_range": "\u003c= 0.8.4"
},
"package": {
"ecosystem": "PyPI",
"name": "Nuitka"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "0.9"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2022-2054"
],
"database_specific": {
"cwe_ids": [
"CWE-77",
"CWE-94"
],
"github_reviewed": true,
"github_reviewed_at": "2022-06-23T06:44:17Z",
"nvd_published_at": "2022-06-12T14:15:00Z",
"severity": "HIGH"
},
"details": "Nuitka 0.8.4 and prior is vulnerable to command injection. A patch is available and anticipated to be part of the `0.9` release.",
"id": "GHSA-4v3r-hqr9-69jf",
"modified": "2024-09-26T14:40:11Z",
"published": "2022-06-13T00:00:18Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2022-2054"
},
{
"type": "WEB",
"url": "https://github.com/Nuitka/Nuitka/commit/1765ffce2a9ab859853210337390de242cd80712"
},
{
"type": "WEB",
"url": "https://github.com/nuitka/nuitka/commit/09647745d7cbb6ff32f9fa948f19d5558b32bcad"
},
{
"type": "PACKAGE",
"url": "https://github.com/nuitka/nuitka"
},
{
"type": "WEB",
"url": "https://github.com/pypa/advisory-database/tree/main/vulns/nuitka/PYSEC-2022-209.yaml"
},
{
"type": "WEB",
"url": "https://huntr.dev/bounties/ea4a842c-c48c-4aae-a599-3305125c63a7"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H",
"type": "CVSS_V3"
},
{
"score": "CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N",
"type": "CVSS_V4"
}
],
"summary": "Command Injection in Nuitka"
}
GHSA-4V4V-WMPC-5VH5
Vulnerability from github – Published: 2025-04-03 18:30 – Updated: 2025-04-03 18:30A vulnerability was found in Tencent Music Entertainment SuperSonic up to 0.9.8. It has been rated as critical. Affected by this issue is some unknown functionality of the file /api/semantic/database/testConnect of the component H2 Database Connection Handler. The manipulation leads to code injection. The attack may be launched remotely. The exploit has been disclosed to the public and may be used.
{
"affected": [],
"aliases": [
"CVE-2025-3164"
],
"database_specific": {
"cwe_ids": [
"CWE-74",
"CWE-94"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2025-04-03T16:15:37Z",
"severity": "MODERATE"
},
"details": "A vulnerability was found in Tencent Music Entertainment SuperSonic up to 0.9.8. It has been rated as critical. Affected by this issue is some unknown functionality of the file /api/semantic/database/testConnect of the component H2 Database Connection Handler. The manipulation leads to code injection. The attack may be launched remotely. The exploit has been disclosed to the public and may be used.",
"id": "GHSA-4v4v-wmpc-5vh5",
"modified": "2025-04-03T18:30:58Z",
"published": "2025-04-03T18:30:58Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2025-3164"
},
{
"type": "WEB",
"url": "https://github.com/tencentmusic/supersonic/issues/2193"
},
{
"type": "WEB",
"url": "https://github.com/tencentmusic/supersonic/issues/2193#issue-2945884387"
},
{
"type": "WEB",
"url": "https://vuldb.com/?ctiid.303110"
},
{
"type": "WEB",
"url": "https://vuldb.com/?id.303110"
},
{
"type": "WEB",
"url": "https://vuldb.com/?submit.542528"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:L/I:L/A:L",
"type": "CVSS_V3"
},
{
"score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:H/UI:N/VC:L/VI:L/VA:L/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X",
"type": "CVSS_V4"
}
]
}
Mitigation
Strategy: Refactoring
Refactor your program so that you do not have to dynamically generate code.
Mitigation
- Run your code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which code can be executed by your product.
- Examples include the Unix chroot jail and AppArmor. In general, managed code may provide some protection.
- This may not be a feasible solution, and it only limits the impact to the operating system; the rest of your application may still be subject to compromise.
- Be careful to avoid CWE-243 and other weaknesses related to jails.
Mitigation MIT-5
Strategy: Input Validation
- Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does.
- When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue."
- Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright.
- To reduce the likelihood of code injection, use stringent allowlists that limit which constructs are allowed. If you are dynamically constructing code that invokes a function, then verifying that the input is alphanumeric might be insufficient. An attacker might still be able to reference a dangerous function that you did not intend to allow, such as system(), exec(), or exit().
Mitigation
Use dynamic tools and techniques that interact with the product using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The product's operation may slow down, but it should not become unstable, crash, or generate incorrect results.
Mitigation MIT-32
Strategy: Compilation or Build Hardening
Run the code in an environment that performs automatic taint propagation and prevents any command execution that uses tainted variables, such as Perl's "-T" switch. This will force the program to perform validation steps that remove the taint, although you must be careful to correctly validate your inputs so that you do not accidentally mark dangerous inputs as untainted (see CWE-183 and CWE-184).
Mitigation MIT-32
Strategy: Environment Hardening
Run the code in an environment that performs automatic taint propagation and prevents any command execution that uses tainted variables, such as Perl's "-T" switch. This will force the program to perform validation steps that remove the taint, although you must be careful to correctly validate your inputs so that you do not accidentally mark dangerous inputs as untainted (see CWE-183 and CWE-184).
Mitigation
For Python programs, it is frequently encouraged to use the ast.literal_eval() function instead of eval, since it is intentionally designed to avoid executing code. However, an adversary could still cause excessive memory or stack consumption via deeply nested structures [REF-1372], so the python documentation discourages use of ast.literal_eval() on untrusted data [REF-1373].
CAPEC-242: Code Injection
An adversary exploits a weakness in input validation on the target to inject new code into that which is currently executing. This differs from code inclusion in that code inclusion involves the addition or replacement of a reference to a code file, which is subsequently loaded by the target and used as part of the code of some application.
CAPEC-35: Leverage Executable Code in Non-Executable Files
An attack of this type exploits a system's trust in configuration and resource files. When the executable loads the resource (such as an image file or configuration file) the attacker has modified the file to either execute malicious code directly or manipulate the target process (e.g. application server) to execute based on the malicious configuration parameters. Since systems are increasingly interrelated mashing up resources from local and remote sources the possibility of this attack occurring is high.
CAPEC-77: Manipulating User-Controlled Variables
This attack targets user controlled variables (DEBUG=1, PHP Globals, and So Forth). An adversary can override variables leveraging user-supplied, untrusted query variables directly used on the application server without any data sanitization. In extreme cases, the adversary can change variables controlling the business logic of the application. For instance, in languages like PHP, a number of poorly set default configurations may allow the user to override variables.