CVE-2023-25657: Nautobot Remote Code Execution Vulnerability
HIGHCVE-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
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).
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.
pip install nautobot>=1.5.7
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
CVE-2023-25657 Affected Nautobot Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
nautobot
|
PyPI |
< 1.5.7
|
1.5.7
|
References
Frequently Asked Questions
What is CVE-2023-25657?
Which Nautobot versions are affected?
What version fixes CVE-2023-25657?
Is nautobot affected?
What is the CVSS score of CVE-2023-25657?
What CWE is associated with CVE-2023-25657?
How can I check PyPI dependencies for CVE-2023-25657?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"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"
}
}