CVE-2023-25657: Nautobot Remote Code Execution Vulnerability

HIGH
Advisory Identifier: GHSA-8mfq-f5wj-vw5m
CVSS 7.5
CWE-94
Published
Advisory Summary

CVE-2023-25657 is a HIGH (CVSS 7.5) remote code execution vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Nautobot libraries in the PyPI ecosystem. The issue involves nautobot vulnerable to remote code execution via jinja2 template rendering. Remediation is available by upgrading affected packages to version 1.5.7.

CVE-2023-25657 at a Glance

CVE Identifier CVE-2023-25657
GHSA Identifier GHSA-8mfq-f5wj-vw5m
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Nautobot
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2023-25657

To remediate this vulnerability, upgrade all affected Nautobot dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

nautobot fixed: 1.5.7
pip install nautobot>=1.5.7
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show nautobot

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2023-25657, inspect your installed packages using pip:

pip show nautobot

Analyze the terminal output to locate any version of Nautobot in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.5.7), your application is affected.

Note: The pip show nautobot command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-94: Improper Control of Generation of Code ('Code Injection'), where 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. In Nautobot, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact _What kind of vulnerability is it? Who is impacted?_ All users of Nautobot versions earlier than 1.5.7 are impacted. In Nautobot 1.5.7 we have enabled sandboxed environments for the Jinja2 template engine used internally for template rendering for the following objects: - `extras.ComputedField` - `extras.CustomLink` - `extras.ExportTemplate` - `extras.Secret` - `extras.Webhook` While we are not aware of any active exploits, we have made this change as a preventative measure to protect against any potential remote code execution attacks utilizing maliciously crafted template code. This change forces the Jinja2 template engine to use a [`SandboxedEnvironment`](https://jinja.palletsprojects.com/en/3.0.x/sandbox/#sandbox) on all new installations of Nautobot. This addresses any potential unsafe code execution everywhere the helper function `nautobot.utilities.utils.render_jinja2` is called. Additionally, our documentation that was previously suggesting the direct use of `jinja2.Template` has been revised to utilize `render_jinja2`. ### Patches _Has the problem been patched? What versions should users upgrade to?_ Yes. Users should upgrade to Nautobot 1.5.7 or newer. ### Workarounds _Is there a way for users to fix or remediate the vulnerability without upgrading?_ ##### Enabling Sandboxed Environments For users that are unable to upgrade to the latest release of Nautobot, you may add the following setting to your `nautobot_config.py` to apply the sandbox environment enforcement: ```python TEMPLATES[1]["OPTIONS"]["environment"] = "jinja2.sandbox.SandboxedEnvironment" ``` After applying this change, you must restart all Nautobot services, including any Celery worker processes. **Note:** *Nautobot specifies two template engines by default, the first being “django” for the Django built-in template engine, and the second being “jinja” for the Jinja2 template engine. This recommended setting will update the second item in the list of template engines, which is the Jinja2 engine.* ##### Restricting Jinja2 using Access Controls For users that are unable to immediately update their configuration such as if a Nautobot service restart is too disruptive to operations, access to provide custom Jinja2 template values may be mitigated using permissions to restrict “change” (write) actions to the affected object types listed in the first section. **Note:** *This solution is intended to be stopgap until you can successfully update your `nautobot_config.py` or upgrade your Nautobot instance to apply the sandboxed environment enforcement.* #### Updating Existing App or Job Code For Nautobot App (formerly plugin) authors or Job authors, additionally we recommend that if you have any custom code that may for example be using `jinaj2.Template` that you no longer use that. Instead, please always use our `nautobot.utilities.utils.render_jinja2` function which will make sure that the centrally-provided Jinja2 template engine with sandboxing enforced is being utilized. Anywhere you’ve been using this pattern: ```python from jinja2 import Template my_template = Template(template_code) config = my_template.render(context) ``` We recommend that you replace it with this pattern: ```python from nautobot.utilities.utils import render_jinja2 config = render_jinja2(template_code, context) ``` ### References _Are there any links users can visit to find out more?_ Please see the Nautobot 1.5.7 release notes. https://docs.nautobot.com/projects/core/en/stable/release-notes/version-1.5/#v157-2023-01-04

CVE-2023-25657 Affected Nautobot Versions

1 component(s)
Fixed Versions:
1.5.7
Product / Package Ecosystem Affected Versions Fixed Version
nautobot
PyPI
< 1.5.7
1.5.7

References

Frequently Asked Questions

What is CVE-2023-25657?
CVE-2023-25657 is a security vulnerability in Nautobot involving Nautobot vulnerable to remote code execution via Jinja2 template rendering under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Nautobot versions are affected?
Affected versions include releases prior to 1.5.7 across affected packages: nautobot.
What version fixes CVE-2023-25657?
Upgrading to 1.5.7 (or the latest patched release for your respective branch) resolves the vulnerability.
Is nautobot affected?
Yes, nautobot is affected in releases prior to 1.5.7. Upgrade your dependency to 1.5.7 or later.
What is the CVSS score of CVE-2023-25657?
CVE-2023-25657 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2023-25657?
CVE-2023-25657 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (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.).
How can I check PyPI dependencies for CVE-2023-25657?
Run the dependency tree command: 'pip show nautobot'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-8mfq-f5wj-vw5m",
  "modified" : "2024-09-25T20:47:41Z",
  "published" : "2023-02-22T00:04:02Z",
  "aliases" : [ "CVE-2023-25657" ],
  "summary" : "Nautobot vulnerable to remote code execution via Jinja2 template rendering",
  "details" : "### Impact\n_What kind of vulnerability is it? Who is impacted?_\n\nAll users of Nautobot versions earlier than 1.5.7 are impacted.\n\nIn Nautobot 1.5.7 we have enabled sandboxed environments for the Jinja2 template engine used internally for template rendering for the following objects:\n\n- `extras.ComputedField`\n- `extras.CustomLink`\n- `extras.ExportTemplate` \n- `extras.Secret`\n- `extras.Webhook`\n\nWhile we are not aware of any active exploits, we have made this change as a preventative measure to protect against any potential remote code execution attacks utilizing maliciously crafted template code.\n\nThis change forces the Jinja2 template engine to use a [`SandboxedEnvironment`](https://jinja.palletsprojects.com/en/3.0.x/sandbox/#sandbox) on all new installations of Nautobot.\n\nThis addresses any potential unsafe code execution everywhere the helper function `nautobot.utilities.utils.render_jinja2` is called. Additionally, our documentation that was previously suggesting the direct use of `jinja2.Template` has been revised to utilize `render_jinja2`.\n\n### Patches\n_Has the problem been patched? What versions should users upgrade to?_\n\nYes. Users should upgrade to Nautobot 1.5.7 or newer.\n\n### Workarounds\n_Is there a way for users to fix or remediate the vulnerability without upgrading?_\n\n##### Enabling Sandboxed Environments\n\nFor users that are unable to upgrade to the latest release of Nautobot, you may add the following setting to your `nautobot_config.py` to apply the sandbox environment enforcement:\n\n```python\nTEMPLATES[1][\"OPTIONS\"][\"environment\"] = \"jinja2.sandbox.SandboxedEnvironment\"\n```\n\nAfter applying this change, you must restart all Nautobot services, including any Celery worker processes.\n\n**Note:** *Nautobot specifies two template engines by default, the first being “django” for the Django built-in template engine, and the second being “jinja” for the Jinja2 template engine. This recommended setting will update the second item in the list of template engines, which is the Jinja2 engine.*\n\n##### Restricting Jinja2 using Access Controls\n\nFor users that are unable to immediately update their configuration such as if a Nautobot service restart is too disruptive to operations, access to provide custom Jinja2 template values may be mitigated using permissions to restrict “change” (write) actions to the affected object types listed in the first section.\n\n**Note:** *This solution is intended to be stopgap until you can successfully update your `nautobot_config.py` or upgrade your Nautobot instance to apply the sandboxed environment enforcement.*\n\n#### Updating Existing App or Job Code\n\nFor Nautobot App (formerly plugin) authors or Job authors, additionally we recommend that if you have any custom code that may for example be using `jinaj2.Template` that you no longer use that. Instead, please always use our `nautobot.utilities.utils.render_jinja2` function which will make sure that the centrally-provided Jinja2 template engine with sandboxing enforced is being utilized.\n\nAnywhere you’ve been using this pattern:\n\n```python\nfrom jinja2 import Template\n\nmy_template = Template(template_code)\nconfig = my_template.render(context)\n```\n\nWe recommend that you replace it with this pattern:\n\n```python\nfrom nautobot.utilities.utils import render_jinja2\n    \nconfig = render_jinja2(template_code, context)\n```\n\n### References\n_Are there any links users can visit to find out more?_\n\nPlease see the Nautobot 1.5.7 release notes. \n\nhttps://docs.nautobot.com/projects/core/en/stable/release-notes/version-1.5/#v157-2023-01-04",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:H/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "nautobot"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.5.7"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/nautobot/nautobot/security/advisories/GHSA-8mfq-f5wj-vw5m"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-25657"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nautobot/nautobot/commit/d47f157e83b0c353bb2b697f911882c71cf90ca0"
  }, {
    "type" : "WEB",
    "url" : "https://docs.nautobot.com/projects/core/en/stable/release-notes/version-1.5/#v157-2023-01-04"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/nautobot/nautobot"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/nautobot/PYSEC-2023-37.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://jinja.palletsprojects.com/en/3.0.x/sandbox/#sandbox"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-94" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-02-22T00:04:02Z",
    "nvd_published_at" : "2023-02-21T21:15:00Z"
  }
}