CVE-2023-25657 is a high-severity (CVSS 7.5) Code Injection vulnerability in nautobot. A fix is available for nautobot — see the affected versions and patch details below.
Remote code execution in Jinja2 template rendering in Nautobot
Exploitation Status
No confirmed exploitation observed yet
- A successful exploit gives an attacker total control of the affected component, not partial access.
- CISA’s own triage has not observed active exploitation or public proof-of-concept code for this CVE as of its last assessment.
Exploitation and automatability from CISA’s SSVC triage for CVE-2023-25657.
EPSS Exploitation Probability
Probability of exploitation in the next 30 days, from FIRST.org EPSS.
How urgent is this, really
Where this sits among everything scored
Real-World Exposure
nautobotReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects PyPI packages — download data is not available via public APIs for these ecosystems.
Description
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.ComputedFieldextras.CustomLinkextras.ExportTemplateextras.Secretextras.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 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:
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:
from jinja2 import Template
my_template = Template(template_code)
config = my_template.render(context)
We recommend that you replace it with this pattern:
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
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 🐍PyPI | nautobot | all versions | 1.5.7pip install --upgrade 'nautobot==1.5.7' |
Affected Products
nautobotnetworktocodeDetection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for nautobot, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update nautobot to 1.5.7 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms CVE-2023-25657 is resolved across your whole dependency graph.
Workarounds
Stop passing untrusted input into the interpreter or shell: call the affected binary with an argument array rather than a composed command string, reject anything outside a strict allowlist of expected values, and run the component under an account that cannot reach beyond the work it legitimately does.
Frequently Asked Questions
Is CVE-2023-25657 in your dependencies?
Find it across PyPI, including transitive dependencies.