GHSA-8MFQ-F5WJ-VW5M

Vulnerability from github – Published: 2023-02-22 00:04 – Updated: 2024-09-25 20:47
VLAI?
Summary
Nautobot vulnerable to remote code execution via Jinja2 template rendering
Details

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

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "PyPI",
        "name": "nautobot"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "1.5.7"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2023-25657"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-94"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2023-02-22T00:04:02Z",
    "nvd_published_at": "2023-02-21T21:15:00Z",
    "severity": "HIGH"
  },
  "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 \u201cdjango\u201d for the Django built-in template engine, and the second being \u201cjinja\u201d 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 \u201cchange\u201d (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\u2019ve 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",
  "id": "GHSA-8mfq-f5wj-vw5m",
  "modified": "2024-09-25T20:47:41Z",
  "published": "2023-02-22T00:04:02Z",
  "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"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H",
      "type": "CVSS_V3"
    },
    {
      "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",
      "type": "CVSS_V4"
    }
  ],
  "summary": "Nautobot vulnerable to remote code execution via Jinja2 template rendering"
}


Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Sightings

Author Source Type Date

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.


Loading…

Detection rules are retrieved from Rulezet.

Loading…

Loading…