Common Weakness Enumeration

CWE-94

Allowed-with-Review

Improper 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.

8285 vulnerabilities reference this CWE, most recent first.

GHSA-JJXG-WW3W-M6HQ

Vulnerability from github – Published: 2023-12-29 12:30 – Updated: 2026-04-28 21:33
VLAI
Details

Improper Control of Generation of Code ('Code Injection') vulnerability in Soft8Soft LLC Verge3D Publishing and E-Commerce.This issue affects Verge3D Publishing and E-Commerce: from n/a through 4.5.2.

Show details on source website

{
  "affected": [],
  "aliases": [
    "CVE-2023-51420"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-94"
    ],
    "github_reviewed": false,
    "github_reviewed_at": null,
    "nvd_published_at": "2023-12-29T10:15:13Z",
    "severity": "CRITICAL"
  },
  "details": "Improper Control of Generation of Code (\u0027Code Injection\u0027) vulnerability in Soft8Soft LLC Verge3D Publishing and E-Commerce.This issue affects Verge3D Publishing and E-Commerce: from n/a through 4.5.2.",
  "id": "GHSA-jjxg-ww3w-m6hq",
  "modified": "2026-04-28T21:33:38Z",
  "published": "2023-12-29T12:30:41Z",
  "references": [
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2023-51420"
    },
    {
      "type": "WEB",
      "url": "https://patchstack.com/database/vulnerability/verge3d/wordpress-verge3d-plugin-4-5-2-remote-code-execution-rce-vulnerability?_s_id=cve"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:H",
      "type": "CVSS_V3"
    }
  ]
}

GHSA-JJXH-2WF9-5QV2

Vulnerability from github – Published: 2022-05-02 03:32 – Updated: 2022-05-02 03:32
VLAI
Details

Insecure method vulnerability in the PDFVIEWER.PDFViewerCtrl.1 ActiveX control (pdfviewer.ocx) in Edraw PDF Viewer Component before 3.2.0.126 allows remote attackers to create and overwrite arbitrary files via a URL argument to the FtpConnect argument and a target filename argument to the FtpDownloadFile method. NOTE: this can be leveraged for code execution by writing to a Startup folder.

Show details on source website

{
  "affected": [],
  "aliases": [
    "CVE-2009-2169"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-94"
    ],
    "github_reviewed": false,
    "github_reviewed_at": null,
    "nvd_published_at": "2009-06-22T22:30:00Z",
    "severity": "HIGH"
  },
  "details": "Insecure method vulnerability in the PDFVIEWER.PDFViewerCtrl.1 ActiveX control (pdfviewer.ocx) in Edraw PDF Viewer Component before 3.2.0.126 allows remote attackers to create and overwrite arbitrary files via a URL argument to the FtpConnect argument and a target filename argument to the FtpDownloadFile method.  NOTE: this can be leveraged for code execution by writing to a Startup folder.",
  "id": "GHSA-jjxh-2wf9-5qv2",
  "modified": "2022-05-02T03:32:33Z",
  "published": "2022-05-02T03:32:33Z",
  "references": [
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2009-2169"
    },
    {
      "type": "WEB",
      "url": "http://archives.neohapsis.com/archives/fulldisclosure/2009-06/0198.html"
    },
    {
      "type": "WEB",
      "url": "http://secunia.com/advisories/35509"
    }
  ],
  "schema_version": "1.4.0",
  "severity": []
}

GHSA-JM34-66CF-QPVR

Vulnerability from github – Published: 2026-04-22 19:59 – Updated: 2026-05-11 13:30
VLAI
Summary
Nuclei: Environment variable disclosure via Response-Derived DSL Expressions
Details

A vulnerability in Nuclei's expression evaluation engine makes it possible for a malicious target server to inject and execute supported DSL expressions. This happens when HTTP response data containing helper/function syntax gets reused by multi-step templates. If the -env-vars / -ev option is explicitly enabled, this can expose host environment variables. That option is off by default, so standard configurations are not affected by the information disclosure risk.

Affected Component

The issue lives in expressions.Evaluate() at pkg/protocols/common/expressions/ and in the unresolved-variable validation path (hasLiteralsOnly()).

Description

expressions.Evaluate() replaces placeholders first, then scans the substituted output for expressions. Because of this two-pass approach, response-derived values (including extractor output and response body content) can be reinterpreted as DSL/helper syntax on the second pass.

When -env-vars (-ev) is enabled, environment variables get merged into the template variable map. A malicious target can return response data containing expressions like {{env_var_name}} which, when reused in a subsequent template request, resolve to actual environment variable values. This can expose sensitive host data like API keys, credentials, and tokens.

Without -ev enabled (the default), injected DSL expressions may still trigger helper functions such as {{md5("test")}}, but this has no meaningful security impact beyond unexpected behavior.

There is also a separate issue in hasLiteralsOnly(): it was evaluating helper expressions while deciding whether {{...}} contained unresolved variables, which caused validation logic to run side-effectful helpers even when the final request kept the value as a literal.

[!NOTE] The -env-vars / -ev option is off by default. Users who have not explicitly turned it on are not affected by the information disclosure aspect of this vulnerability.

Affected Users

  • CLI users running multi-step templates (with extractors or flow-based request chaining) that reuse response-derived values against untrusted or attacker-controlled targets, with the -ev flag enabled.
  • SDK users who have integrated Nuclei into platforms where EnvironmentVariables is set to true and scan targets are not fully trusted.

Patches

  • The vulnerability is fixed in Nuclei v3.8.0. Upgrading to this version is strongly recommended.
  • Relevant fix references: #7221, #7321.

Mitigation

Upgrade to Nuclei v3.8.0. The updated evaluation logic now collects expressions from the original template text before placeholder substitution and only evaluates those template-authored expressions.

If you have -ev enabled, disable it when scanning untrusted targets to avoid environment variable disclosure.

Workarounds

If upgrading is not an option right now, make sure -env-vars / -ev is not enabled when running multi-step templates against untrusted targets.

Acknowledgments

Nuclei thanks @gnuletik for reporting this issue through responsible disclosure via security@projectdiscovery.io

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "Go",
        "name": "github.com/projectdiscovery/nuclei/v3"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "3.0.0"
            },
            {
              "fixed": "3.8.0"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-41645"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-94"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-04-22T19:59:14Z",
    "nvd_published_at": "2026-05-08T04:16:18Z",
    "severity": "MODERATE"
  },
  "details": "A vulnerability in Nuclei\u0027s expression evaluation engine makes it possible for a malicious target server to inject and execute supported DSL expressions. This happens when HTTP response data containing helper/function syntax gets reused by multi-step templates. If the `-env-vars` / `-ev` option is explicitly enabled, this can expose host environment variables. That option is off by default, so standard configurations are not affected by the information disclosure risk.\n\n**Affected Component**\n\nThe issue lives in `expressions.Evaluate()` at `pkg/protocols/common/expressions/` and in the unresolved-variable validation path (`hasLiteralsOnly()`).\n\n**Description**\n\n`expressions.Evaluate()` replaces placeholders first, then scans the substituted output for expressions. Because of this two-pass approach, response-derived values (including extractor output and response body content) can be reinterpreted as DSL/helper syntax on the second pass.\n\nWhen `-env-vars` (`-ev`) is enabled, environment variables get merged into the template variable map. A malicious target can return response data containing expressions like `{{env_var_name}}` which, when reused in a subsequent template request, resolve to actual environment variable values. This can expose sensitive host data like API keys, credentials, and tokens.\n\nWithout `-ev` enabled (the default), injected DSL expressions may still trigger helper functions such as `{{md5(\"test\")}}`, but this has no meaningful security impact beyond unexpected behavior.\n\nThere is also a separate issue in `hasLiteralsOnly()`: it was evaluating helper expressions while deciding whether `{{...}}` contained unresolved variables, which caused validation logic to run side-effectful helpers even when the final request kept the value as a literal.\n\n\u003e [!NOTE]\nThe `-env-vars` / `-ev` option is off by default. Users who have not explicitly turned it on are not affected by the information disclosure aspect of this vulnerability.\n\n**Affected Users**\n\n- **CLI users** running multi-step templates (with extractors or flow-based request chaining) that reuse response-derived values against untrusted or attacker-controlled targets, with the `-ev` flag enabled.\n- **SDK users** who have integrated Nuclei into platforms where `EnvironmentVariables` is set to `true` and scan targets are not fully trusted.\n\n**Patches**\n\n- The vulnerability is fixed in Nuclei v3.8.0. Upgrading to this version is strongly recommended.\n- Relevant fix references: #7221, #7321.\n\n**Mitigation**\n\nUpgrade to Nuclei v3.8.0. The updated evaluation logic now collects expressions from the original template text before placeholder substitution and only evaluates those template-authored expressions.\n\nIf you have `-ev` enabled, disable it when scanning untrusted targets to avoid environment variable disclosure.\n\n**Workarounds**\n\nIf upgrading is not an option right now, make sure `-env-vars` / `-ev` is not enabled when running multi-step templates against untrusted targets.\n\n**Acknowledgments**\n\nNuclei thanks @gnuletik for reporting this issue through responsible disclosure via security@projectdiscovery.io",
  "id": "GHSA-jm34-66cf-qpvr",
  "modified": "2026-05-11T13:30:34Z",
  "published": "2026-04-22T19:59:14Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/projectdiscovery/nuclei/security/advisories/GHSA-jm34-66cf-qpvr"
    },
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-41645"
    },
    {
      "type": "WEB",
      "url": "https://github.com/projectdiscovery/nuclei/pull/7221"
    },
    {
      "type": "WEB",
      "url": "https://github.com/projectdiscovery/nuclei/pull/7321"
    },
    {
      "type": "WEB",
      "url": "https://github.com/projectdiscovery/nuclei/commit/6c803c74d193f85f8a6d9803ce493fd302cad0eb"
    },
    {
      "type": "WEB",
      "url": "https://github.com/projectdiscovery/nuclei/commit/d2217320162d5782ca7cb95bef9dda17063818f3"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/projectdiscovery/nuclei"
    },
    {
      "type": "WEB",
      "url": "https://github.com/projectdiscovery/nuclei/releases/tag/v3.8.0"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:N/A:N",
      "type": "CVSS_V3"
    }
  ],
  "summary": "Nuclei: Environment variable disclosure via Response-Derived DSL Expressions"
}

GHSA-JM3M-G3QW-QR2V

Vulnerability from github – Published: 2022-05-01 07:30 – Updated: 2025-04-03 18:30
VLAI
Details

PHP remote file inclusion vulnerability in player/includes/common.php in Teake Nutma Foing, as modified in Fully Modded phpBB (phpbbfm) 2021.4.40, allows remote attackers to execute arbitrary PHP code via a URL in the phpbb_root_path parameter.

Show details on source website

{
  "affected": [],
  "aliases": [
    "CVE-2006-5610"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-94"
    ],
    "github_reviewed": false,
    "github_reviewed_at": null,
    "nvd_published_at": "2006-10-31T00:07:00Z",
    "severity": "HIGH"
  },
  "details": "PHP remote file inclusion vulnerability in player/includes/common.php in Teake Nutma Foing, as modified in Fully Modded phpBB (phpbbfm) 2021.4.40, allows remote attackers to execute arbitrary PHP code via a URL in the phpbb_root_path parameter.",
  "id": "GHSA-jm3m-g3qw-qr2v",
  "modified": "2025-04-03T18:30:26Z",
  "published": "2022-05-01T07:30:07Z",
  "references": [
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2006-5610"
    },
    {
      "type": "WEB",
      "url": "http://secunia.com/advisories/22499"
    }
  ],
  "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"
    }
  ]
}

GHSA-JM3V-M7PQ-RWRH

Vulnerability from github – Published: 2022-05-14 01:45 – Updated: 2022-05-14 01:45
VLAI
Details

Vanilla 2.6.x before 2.6.4 allows remote code execution.

Show details on source website

{
  "affected": [],
  "aliases": [
    "CVE-2018-18903"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-94"
    ],
    "github_reviewed": false,
    "github_reviewed_at": null,
    "nvd_published_at": "2018-11-03T05:29:00Z",
    "severity": "CRITICAL"
  },
  "details": "Vanilla 2.6.x before 2.6.4 allows remote code execution.",
  "id": "GHSA-jm3v-m7pq-rwrh",
  "modified": "2022-05-14T01:45:29Z",
  "published": "2022-05-14T01:45:29Z",
  "references": [
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2018-18903"
    },
    {
      "type": "WEB",
      "url": "https://github.com/vanilla/vanilla/releases/tag/Vanilla_2.6.4"
    },
    {
      "type": "WEB",
      "url": "https://open.vanillaforums.com/discussion/36771/security-update-vanilla-2-6-4"
    },
    {
      "type": "WEB",
      "url": "https://srcincite.io/blog/2018/10/02/old-school-pwning-with-new-school-tricks-vanilla-forums-remote-code-execution.html"
    }
  ],
  "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-JM69-H2QJ-3QWX

Vulnerability from github – Published: 2022-05-14 01:47 – Updated: 2022-05-14 01:47
VLAI
Details

In YXcms 1.4.7, protected/apps/appmanage/controller/indexController.php allow remote authenticated Administrators to execute any PHP code by creating a ZIP archive containing a config.php file, hosting the .zip file at an external URL, and visiting index.php?r=appmanage/index/onlineinstall&url= followed by that URL. This is related to the onlineinstall and import functions.

Show details on source website

{
  "affected": [],
  "aliases": [
    "CVE-2018-19404"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-94"
    ],
    "github_reviewed": false,
    "github_reviewed_at": null,
    "nvd_published_at": "2018-11-21T00:29:00Z",
    "severity": "HIGH"
  },
  "details": "In YXcms 1.4.7, protected/apps/appmanage/controller/indexController.php allow remote authenticated Administrators to execute any PHP code by creating a ZIP archive containing a config.php file, hosting the .zip file at an external URL, and visiting index.php?r=appmanage/index/onlineinstall\u0026url= followed by that URL. This is related to the onlineinstall and import functions.",
  "id": "GHSA-jm69-h2qj-3qwx",
  "modified": "2022-05-14T01:47:08Z",
  "published": "2022-05-14T01:47:08Z",
  "references": [
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2018-19404"
    },
    {
      "type": "WEB",
      "url": "https://github.com/HF9/yxcms-code-audit/blob/master/Any%20PHP%20Code%20Execution"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.0/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H",
      "type": "CVSS_V3"
    }
  ]
}

GHSA-JM9X-4PC8-3RV4

Vulnerability from github – Published: 2022-05-24 16:54 – Updated: 2024-04-04 01:49
VLAI
Details

The groundhogg plugin before 1.3.5 for WordPress has wp-admin/admin-ajax.php?action=bulk_action_listener remote code execution.

Show details on source website

{
  "affected": [],
  "aliases": [
    "CVE-2019-15647"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-94"
    ],
    "github_reviewed": false,
    "github_reviewed_at": null,
    "nvd_published_at": "2019-08-27T12:15:00Z",
    "severity": "HIGH"
  },
  "details": "The groundhogg plugin before 1.3.5 for WordPress has wp-admin/admin-ajax.php?action=bulk_action_listener remote code execution.",
  "id": "GHSA-jm9x-4pc8-3rv4",
  "modified": "2024-04-04T01:49:04Z",
  "published": "2022-05-24T16:54:57Z",
  "references": [
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2019-15647"
    },
    {
      "type": "WEB",
      "url": "https://wordpress.org/plugins/groundhogg/#developers"
    },
    {
      "type": "WEB",
      "url": "https://wpvulndb.com/vulnerabilities/9834"
    },
    {
      "type": "WEB",
      "url": "https://www.pluginvulnerabilities.com/2019/04/05/our-proactive-monitoring-caught-an-authenticated-remote-code-execution-rce-vulnerability-being-introduced-in-to-groundhogg"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.0/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H",
      "type": "CVSS_V3"
    }
  ]
}

GHSA-JMF2-H546-V465

Vulnerability from github – Published: 2022-05-24 17:21 – Updated: 2022-05-24 17:21
VLAI
Details

An issue was discovered in Mattermost Desktop App before 4.3.0 on macOS. It allows dylib injection.

Show details on source website

{
  "affected": [],
  "aliases": [
    "CVE-2019-20856"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-427",
      "CWE-94"
    ],
    "github_reviewed": false,
    "github_reviewed_at": null,
    "nvd_published_at": "2020-06-19T15:15:00Z",
    "severity": "HIGH"
  },
  "details": "An issue was discovered in Mattermost Desktop App before 4.3.0 on macOS. It allows dylib injection.",
  "id": "GHSA-jmf2-h546-v465",
  "modified": "2022-05-24T17:21:12Z",
  "published": "2022-05-24T17:21:12Z",
  "references": [
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2019-20856"
    },
    {
      "type": "WEB",
      "url": "https://mattermost.com/security-updates"
    }
  ],
  "schema_version": "1.4.0",
  "severity": []
}

GHSA-JMFJ-RGC6-43MH

Vulnerability from github – Published: 2022-05-17 02:17 – Updated: 2022-05-17 02:17
VLAI
Details

Unspecified vulnerability in Adobe Flash Player for Linux 10.0.12.36, and 9.0.151.0 and earlier, allows remote attackers to execute arbitrary code via a crafted SWF file.

Show details on source website

{
  "affected": [],
  "aliases": [
    "CVE-2008-5499"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-94"
    ],
    "github_reviewed": false,
    "github_reviewed_at": null,
    "nvd_published_at": "2008-12-18T00:30:00Z",
    "severity": "HIGH"
  },
  "details": "Unspecified vulnerability in Adobe Flash Player for Linux 10.0.12.36, and 9.0.151.0 and earlier, allows remote attackers to execute arbitrary code via a crafted SWF file.",
  "id": "GHSA-jmfj-rgc6-43mh",
  "modified": "2022-05-17T02:17:31Z",
  "published": "2022-05-17T02:17:31Z",
  "references": [
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2008-5499"
    },
    {
      "type": "WEB",
      "url": "https://exchange.xforce.ibmcloud.com/vulnerabilities/47445"
    },
    {
      "type": "WEB",
      "url": "http://lists.opensuse.org/opensuse-security-announce/2008-12/msg00006.html"
    },
    {
      "type": "WEB",
      "url": "http://osvdb.org/50796"
    },
    {
      "type": "WEB",
      "url": "http://secunia.com/advisories/33221"
    },
    {
      "type": "WEB",
      "url": "http://secunia.com/advisories/33267"
    },
    {
      "type": "WEB",
      "url": "http://secunia.com/advisories/33294"
    },
    {
      "type": "WEB",
      "url": "http://secunia.com/advisories/34226"
    },
    {
      "type": "WEB",
      "url": "http://security.gentoo.org/glsa/glsa-200903-23.xml"
    },
    {
      "type": "WEB",
      "url": "http://www.adobe.com/support/security/bulletins/apsb08-24.html"
    },
    {
      "type": "WEB",
      "url": "http://www.redhat.com/support/errata/RHSA-2008-1047.html"
    },
    {
      "type": "WEB",
      "url": "http://www.securityfocus.com/bid/32896"
    },
    {
      "type": "WEB",
      "url": "http://www.securitytracker.com/id?1021458"
    },
    {
      "type": "WEB",
      "url": "http://www.vupen.com/english/advisories/2008/3449"
    }
  ],
  "schema_version": "1.4.0",
  "severity": []
}

GHSA-JMHJ-WQ27-83JG

Vulnerability from github – Published: 2022-05-14 02:56 – Updated: 2022-05-14 02:56
VLAI
Details

Static code injection vulnerability in Simploo CMS 1.7.1 and earlier allows remote authenticated users to inject arbitrary PHP code into config/custom/base.ini.php via the ftpserver parameter (FTP-Server field) to the sicore/updates/optionssav operation for index.php.

Show details on source website

{
  "affected": [],
  "aliases": [
    "CVE-2011-0635"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-94"
    ],
    "github_reviewed": false,
    "github_reviewed_at": null,
    "nvd_published_at": "2011-01-22T22:00:00Z",
    "severity": "MODERATE"
  },
  "details": "Static code injection vulnerability in Simploo CMS 1.7.1 and earlier allows remote authenticated users to inject arbitrary PHP code into config/custom/base.ini.php via the ftpserver parameter (FTP-Server field) to the sicore/updates/optionssav operation for index.php.",
  "id": "GHSA-jmhj-wq27-83jg",
  "modified": "2022-05-14T02:56:35Z",
  "published": "2022-05-14T02:56:35Z",
  "references": [
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2011-0635"
    },
    {
      "type": "WEB",
      "url": "https://exchange.xforce.ibmcloud.com/vulnerabilities/64826"
    },
    {
      "type": "WEB",
      "url": "http://osvdb.org/70487"
    },
    {
      "type": "WEB",
      "url": "http://secunia.com/advisories/42953"
    },
    {
      "type": "WEB",
      "url": "http://www.exploit-db.com/exploits/16016"
    },
    {
      "type": "WEB",
      "url": "http://www.securityfocus.com/archive/1/515809/100/0/threaded"
    },
    {
      "type": "WEB",
      "url": "http://www.securityfocus.com/bid/45906"
    }
  ],
  "schema_version": "1.4.0",
  "severity": []
}

Mitigation
Architecture and Design

Strategy: Refactoring

Refactor your program so that you do not have to dynamically generate code.

Mitigation
Architecture and Design
  • 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
Implementation

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
Testing

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
Operation

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
Operation

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
Implementation

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.