CVE-2024-23345: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (CWE-79)
value: Nautobot is a Network Source of Truth and Network Automation Platform built as a web application.  All users of Nautobot versions earlier than 1.6.10 or 2.1.2 are potentially impacted by a cross-site scripting vulnerability. Due to inadequate input sanitization, any user-editable fields that support Markdown rendering, including are potentially susceptible to cross-site scripting (XSS) attacks via maliciously crafted data. This issue is fixed in Nautobot versions 1.6.10 and 2.1.2.
CWE description: The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
CVSS v3 base score: 5.4
Published: 2024-01-23T00:15Z
Repository: https://github.com/nautobot/nautobot
Language: Python
Files changed: changes/5133.added, changes/5133.dependencies, changes/5133.security, nautobot/core/constants.py, nautobot/core/forms/fields.py, nautobot/core/settings.py, nautobot/core/templatetags/helpers.py, nautobot/core/tests/test_templatetags_helpers.py, nautobot/core/tests/test_views.py, nautobot/core/utils/logging.py, nautobot/docs/development/jobs/index.md, nautobot/docs/user-guide/administration/configuration/optional-settings.md, nautobot/docs/user-guide/platform-functionality/note.md, nautobot/docs/user-guide/platform-functionality/template-filters.md, nautobot/extras/forms/forms.py, nautobot/extras/models/jobs.py, poetry.lock, pyproject.toml
Commit date: 2024-01-19 16:37:24 -0500
Commit message: Sanitize `render_markdown()` output with `nh3` library (#5133)

* Fix GHSA-v4xv-795h-rv4h.

* Renumber change fragments

* Address review feedback

* Test fix

* Ruff

* Review feedback

* Update nautobot/core/forms/fields.py
Diff: diff --git a/changes/5133.added b/changes/5133.added
new file mode 100644
index 0000000000..373cf85d38
--- /dev/null
+++ b/changes/5133.added
@@ -0,0 +1 @@
+Enhanced Markdown-supporting fields (`comments`, `description`, Notes, Job log entries, etc.) to also permit the use of a limited subset of "safe" HTML tags and attributes.
diff --git a/changes/5133.dependencies b/changes/5133.dependencies
new file mode 100644
index 0000000000..583cbd88ea
--- /dev/null
+++ b/changes/5133.dependencies
@@ -0,0 +1 @@
+Added `nh3` HTML sanitization library as a dependency.
diff --git a/changes/5133.security b/changes/5133.security
new file mode 100644
index 0000000000..f6aa67ca00
--- /dev/null
+++ b/changes/5133.security
@@ -0,0 +1 @@
+Fixed an XSS vulnerability ([GHSA-v4xv-795h-rv4h](https://github.com/nautobot/nautobot/security/advisories/GHSA-v4xv-795h-rv4h)) in the `render_markdown()` utility function used to render comments, notes, job log entries, etc.
diff --git a/nautobot/core/constants.py b/nautobot/core/constants.py
index 8ec528c856..8ac4676114 100644
--- a/nautobot/core/constants.py
+++ b/nautobot/core/constants.py
@@ -1,5 +1,9 @@
+from copy import deepcopy
+
+import nh3
+
 SEARCH_MAX_RESULTS = 15
 
 #
 # Filter lookup expressions
 #
@@ -30,10 +34,39 @@ FILTER_NUMERIC_BASED_LOOKUP_MAP = {
     "gt": "gt",
 }
 
 FILTER_NEGATION_LOOKUP_MAP = {"n": "exact"}
 
+#
+# User input sanitization
+#
+
+# Subset of the HTML tags allowed by default by ammonia:
+# https://github.com/rust-ammonia/ammonia/blob/master/src/lib.rs
+HTML_ALLOWED_TAGS = nh3.ALLOWED_TAGS - {
+    # no image maps at present
+    "area",
+    "map",
+    # no document-level markup at present
+    "article",
+    "aside",
+    "footer",
+    "header",
+    "nav",
+    # miscellaneous out-of-scope for now
+    "data",
+    "dfn",
+    "figcaption",
+    "figure",
+}
+
+# Variant of the HTML attributes allowed by default by ammonia:
+# https://github.com/rust-ammonia/ammonia/blob/master/src/lib.rs
+# at present we just copy nh3.ALLOWED_ATTRIBUTES but we can modify this later as desired and appropriate
+HTML_ALLOWED_ATTRIBUTES = deepcopy(nh3.ALLOWED_ATTRIBUTES)
+
+
 #
 # Reserved Names
 #
 
 RESERVED_NAMES_FOR_OBJECT_DETAIL_VIEW_SCHEMA = ["Other Fields", "Object Details"]
diff --git a/nautobot/core/forms/fields.py b/nautobot/core/forms/fields.py
index 46be0b097c..f277f1c57f 100644
--- a/nautobot/core/forms/fields.py
+++ b/nautobot/core/forms/fields.py
@@ -7,11 +7,13 @@ from django.conf import settings
 from django.contrib.contenttypes.models import ContentType
 from django.contrib.postgres.forms import SimpleArrayField
 from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist, ValidationError
 from django.db.models import Q
 from django.forms.fields import BoundField, InvalidJSONInput, JSONField as _JSONField
+from django.templatetags.static import static
 from django.urls import reverse
+from django.utils.html import format_html
 import django_filters
 from netaddr import EUI
 from netaddr.core import AddrFormatError
 
 from nautobot.core import choices as core_choices, forms
@@ -370,16 +372,20 @@ class CommentField(django_forms.CharField):
     A textarea with support for Markdown rendering. Exists mostly just to add a standard help_text.
     """
 
     widget = django_forms.Textarea
     default_label = ""
-    # TODO: Port Markdown cheat sheet to internal documentation
-    default_helptext = (
-        '<i class="mdi mdi-information-outline"></i> '
-        '<a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet" target="_blank">'
-        "Markdown</a> syntax is supported"
-    )
+
+    @property
+    def default_helptext(self):
+        # TODO: Port Markdown cheat sheet to internal documentation
+        return format_html(
+            '<i class="mdi mdi-information-outline"></i> '
+            '<a href="https://www.markdownguide.org/cheat-sheet/#basic-syntax" rel="noopener noreferrer">Markdown</a> '
+            'syntax is supported, as well as <a href="{}#render_markdown">a limited subset of HTML</a>.',
+            static("docs/user-guide/platform-functionality/template-filters.html"),
+        )
 
     def __init__(self, *args, **kwargs):
         required = kwargs.pop("required", False)
         label = kwargs.pop("label", self.default_label)
         help_text = kwargs.pop("help_text", self.default_helptext)
diff --git a/nautobot/core/settings.py b/nautobot/core/settings.py
index 983ea06053..24d2f111fc 100644
--- a/nautobot/core/settings.py
+++ b/nautobot/core/settings.py
@@ -680,11 +680,12 @@ CONSTANCE_CONFIG = {
         # Use custom field type defined above
         field_type="release_check_url_field",
     ),
     "SUPPORT_MESSAGE": ConstanceConfigItem(
         default="",
-        help_text="Help message to include on 4xx and 5xx error pages. Markdown is supported.\n"
+        help_text="Help message to include on 4xx and 5xx error pages. "
+        "Markdown is supported, as are some HTML tags and attributes.\n"
         "If unspecified, instructions to join Network to Code's Slack community will be provided.",
     ),
 }
 
 CONSTANCE_CONFIG_FIELDSETS = {
diff --git a/nautobot/core/templatetags/helpers.py b/nautobot/core/templatetags/helpers.py
index 58f2626e5c..d86745c8ad 100644
--- a/nautobot/core/templatetags/helpers.py
+++ b/nautobot/core/templatetags/helpers.py
@@ -6,20 +6,20 @@ import re
 from django import template
 from django.conf import settings
 from django.contrib.staticfiles.finders import find
 from django.templatetags.static import static, StaticNode
 from django.urls import NoReverseMatch, reverse
-from django.utils.html import format_html, strip_tags
+from django.utils.html import format_html
 from django.utils.safestring import mark_safe
 from django.utils.text import slugify as django_slugify
 from django_jinja import library
 from markdown import markdown
 import yaml
 
 from nautobot.apps.config import get_app_settings_or_config
 from nautobot.core import forms
-from nautobot.core.utils import color, config, data, lookup
+from nautobot.core.utils import color, config, data, logging as nautobot_logging, lookup
 from nautobot.core.utils.requests import add_nautobot_version_query_param_to_url
 
 # S308 is suspicious-mark-safe-usage, but these are all using static strings that we know to be safe
 HTML_TRUE = mark_safe('<span class="text-success"><i class="mdi mdi-check-bold" title="Yes"></i></span>')  # noqa: S308
 HTML_FALSE = mark_safe('<span class="text-danger"><i class="mdi mdi-close-thick" title="No"></i></span>')  # noqa: S308
@@ -168,21 +168,16 @@ def render_markdown(value):
     Render text as Markdown
 
     Example:
         {{ text | render_markdown }}
     """
-    # Strip HTML tags
-    value = strip_tags(value)
-
-    # Sanitize Markdown links
-    schemes = "|".join(settings.ALLOWED_URL_SCHEMES)
-    pattern = rf"\[(.+)\]\((?!({schemes})).*:(.+)\)"
-    value = re.sub(pattern, "[\\1](\\3)", value, flags=re.IGNORECASE)
-
     # Render Markdown
     html = markdown(value, extensions=["fenced_code", "tables"])
 
+    # Sanitize rendered HTML
+    html = nautobot_logging.clean_html(html)
+
     return mark_safe(html)  # noqa: S308  # suspicious-mark-safe-usage, OK here since we sanitized the string earlier
 
 
 @library.filter()
 @register.filter()
diff --git a/nautobot/core/tests/test_templatetags_helpers.py b/nautobot/core/tests/test_templatetags_helpers.py
index 02e774c6db..240e3e6071 100644
--- a/nautobot/core/tests/test_templatetags_helpers.py
+++ b/nautobot/core/tests/test_templatetags_helpers.py
@@ -77,13 +77,28 @@ class NautobotTemplatetagsHelperTest(TestCase):
         self.assertEqual(helpers.render_markdown("*italics*"), "<p><em>italics</em></p>")
         self.assertEqual(
             helpers.render_markdown("**bold and _italics_**"), "<p><strong>bold and <em>italics</em></strong></p>"
         )
         self.assertEqual(helpers.render_markdown("* list"), "<ul>\n<li>list</li>\n</ul>")
-        self.assertEqual(
+        self.assertHTMLEqual(
             helpers.render_markdown("[I am a link](https://www.example.com)"),
-            '<p><a href="https://www.example.com">I am a link</a></p>',
+            '<p><a href="https://www.example.com" rel="noopener noreferrer">I am a link</a></p>',
+        )
+
+    def test_render_markdown_security(self):
+        self.assertEqual(helpers.render_markdown('<script>alert("XSS")</script>'), "")
+        self.assertHTMLEqual(
+            helpers.render_markdown('[link](javascript:alert("XSS"))'),
+            '<p><a title="XSS" rel="noopener noreferrer">link</a>)</p>',  # the trailing ) seems weird to me, but...
+        )
+        self.assertHTMLEqual(
+            helpers.render_markdown(
+                "[link\nJS]"
+                "(&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A"  # '(javascript:'
+                "&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29)"  # 'alert("XSS"))'
+            ),
+            '<p><a rel="noopener noreferrer">link JS</a></p>',
         )
 
     def test_render_json(self):
         self.assertEqual(
             helpers.render_json({"first": [1, 2, 3]}), '{\n    "first": [\n        1,\n        2,\n        3\n    ]\n}'
@@ -238,12 +253,12 @@ class NautobotTemplatetagsHelperTest(TestCase):
             del settings.SUPPORT_MESSAGE
             with override_config():
                 self.assertHTMLEqual(
                     helpers.support_message(),
                     "<p>If further assistance is required, please join the <code>#nautobot</code> channel "
-                    'on <a href="https://slack.networktocode.com/">Network to Code\'s Slack community</a> '
-                    "and post your question.</p>",
+                    'on <a href="https://slack.networktocode.com/" rel="noopener noreferrer">Network to Code\'s '
+                    "Slack community</a> and post your question.</p>",
                 )
 
             with override_config(SUPPORT_MESSAGE="Reach out to your support team for assistance."):
                 self.assertHTMLEqual(
                     helpers.support_message(),
diff --git a/nautobot/core/tests/test_views.py b/nautobot/core/tests/test_views.py
index 097e006ab1..94f1a1f63e 100644
--- a/nautobot/core/tests/test_views.py
+++ b/nautobot/core/tests/test_views.py
@@ -364,13 +364,13 @@ class ErrorPagesTestCase(TestCase):
         with self.assertTemplateUsed("404.html"):
             response = self.client.get("/foo/bar")
         self.assertContains(response, "Network to Code", status_code=404)
         response_content = response.content.decode(response.charset)
         self.assertInHTML(
-            "If further assistance is required, please join the <code>#nautobot</code> channel "
-            'on <a href="https://slack.networktocode.com/">Network to Code\'s Slack community</a> '
-            "and post your question.",
+            "If further assistance is required, please join the <code>#nautobot</code> channel on "
+            '<a href="https://slack.networktocode.com/" rel="noopener noreferrer">Network to Code\'s '
+            "Slack community</a> and post your question.",
             response_content,
         )
 
     @override_settings(DEBUG=False, SUPPORT_MESSAGE="Hello world!")
     def test_404_custom_support_message(self):
@@ -390,20 +390,20 @@ class ErrorPagesTestCase(TestCase):
             self.client.raise_request_exception = False
             response = self.client.get(url)
         self.assertContains(response, "Network to Code", status_code=500)
         response_content = response.content.decode(response.charset)
         self.assertInHTML(
-            "If further assistance is required, please join the <code>#nautobot</code> channel "
-            'on <a href="https://slack.networktocode.com/">Network to Code\'s Slack community</a> '
-            "and post your question.",
+            "If further assistance is required, please join the <code>#nautobot</code> channel on "
+            '<a href="https://slack.networktocode.com/" rel="noopener noreferrer">Network to Code\'s '
+            "Slack community</a> and post your question.",
             response_content,
         )
 
     @override_settings(DEBUG=False, SUPPORT_MESSAGE="Hello world!")
     @mock.patch("nautobot.core.views.HomeView.get", side_effect=Exception)
     def test_500_custom_support_message(self, mock_get):
-        """Nautobot's custom 500 page should be used and should include a default support message."""
+        """Nautobot's custom 500 page should be used and should include a custom support message if defined."""
         url = reverse("home")
         with self.assertTemplateUsed("500.html"):
             self.client.raise_request_exception = False
             response = self.client.get(url)
         self.assertNotContains(response, "Network to Code", status_code=500)
diff --git a/nautobot/core/utils/logging.py b/nautobot/core/utils/logging.py
index 0fec741e3a..28c7ef7486 100644
--- a/nautobot/core/utils/logging.py
+++ b/nautobot/core/utils/logging.py
@@ -1,11 +1,14 @@
-"""Utilities for working with log messages and similar features."""
+"""Utilities for working with log messages and similar user-authored data."""
 
 import logging
 import re
 
 from django.conf import settings
+import nh3
+
+from nautobot.core import constants
 
 logger = logging.getLogger(__name__)
 
 
 def sanitize(dirty, replacement="(redacted)"):
@@ -45,5 +48,15 @@ def sanitize(dirty, replacement="(redacted)"):
 
         return clean
 
     logger.warning("No sanitizer support for %s data", type(dirty))
     return dirty
+
+
+def clean_html(html):
+    """Use nh3/ammonia to strip out all HTML tags and attributes except those explicitly permitted."""
+    return nh3.clean(
+        html,
+        tags=constants.HTML_ALLOWED_TAGS,
+        attributes=constants.HTML_ALLOWED_ATTRIBUTES,
+        url_schemes=set(settings.ALLOWED_URL_SCHEMES),
+    )
diff --git a/nautobot/docs/development/jobs/index.md b/nautobot/docs/development/jobs/index.md
index f0bae3b1f2..8e6ab6fd70 100644
--- a/nautobot/docs/development/jobs/index.md
+++ b/nautobot/docs/development/jobs/index.md
@@ -111,11 +111,11 @@ This is the human-friendly name of your job, as will be displayed in the Nautobo
     In some UI elements and API endpoints, the class name is displayed in addition to or in place of this attribute, so even if defining this attribute, you should still choose an appropriately explanatory class name as well.
 
 #### `description`
 
 An optional human-friendly description of what this job does.
-This can accept either plain text or Markdown-formatted text. It can also be multiple lines:
+This can accept either plain text, Markdown-formatted text, or [a limited subset of HTML](../../user-guide/platform-functionality/template-filters.md#render_markdown). It can also be multiple lines:
 
 ```python
 class ExampleJob(Job):
     class Meta:
         description = """
@@ -510,11 +510,11 @@ To skip writing a log entry to the database, set the `skip_db_logging` key in th
     class MyJob(Job):
         def run(self):
             logger.info("This job is running!", extra={"skip_db_logging": True})
     ```
 
-Markdown rendering is supported for log messages.
+Markdown rendering is supported for log messages, as well as [a limited subset of HTML](../../user-guide/platform-functionality/template-filters.md#render_markdown).
 
 +/- 1.3.4
     As a security measure, the `message` passed to any of these methods will be passed through the `nautobot.core.utils.logging.sanitize()` function in an attempt to strip out information such as usernames/passwords that should not be saved to the logs. This is of course best-effort only, and Job authors should take pains to ensure that such information is not passed to the logging APIs in the first place. The set of redaction rules used by the `sanitize()` function can be configured as [settings.SANITIZER_PATTERNS](../../user-guide/administration/configuration/optional-settings.md#sanitizer_patterns).
 
 +/- 2.0.0
diff --git a/nautobot/docs/user-guide/administration/configuration/optional-settings.md b/nautobot/docs/user-guide/administration/configuration/optional-settings.md
index 43d56978b0..3b0fff6975 100644
--- a/nautobot/docs/user-guide/administration/configuration/optional-settings.md
+++ b/nautobot/docs/user-guide/administration/configuration/optional-settings.md
@@ -962,11 +962,11 @@ If set to `False`, unknown/unrecognized filter parameters will be discarded and
 
 +++ 2.0.2
 
 Default: `""`
 
-A message to include on error pages (status code 403, 404, 500, etc.) when an error occurs. You can configure this to direct users to the appropriate contact(s) within your organization that provide support for Nautobot. Markdown formatting is supported within this message (raw HTML is not).
+A message to include on error pages (status code 403, 404, 500, etc.) when an error occurs. You can configure this to direct users to the appropriate contact(s) within your organization that provide support for Nautobot. Markdown formatting is supported within this message, as well as [a limited subset of HTML](../../platform-functionality/template-filters.md#render_markdown).
 
 If unset, the default message that will appear is `If further assistance is required, please join the #nautobot channel on [Network to Code's Slack community](https://slack.networktocode.com) and post your question.`
 
 !!! tip
     If you do not set a value for this setting in your `nautobot_config.py`, it can be configured dynamically by an admin user via the Nautobot Admin UI. If you do have a value for this setting in `nautobot_config.py`, it will override any dynamically configured value.
diff --git a/nautobot/docs/user-guide/platform-functionality/note.md b/nautobot/docs/user-guide/platform-functionality/note.md
index d97e14214c..5665b3b103 100644
--- a/nautobot/docs/user-guide/platform-functionality/note.md
+++ b/nautobot/docs/user-guide/platform-functionality/note.md
@@ -2,6 +2,6 @@
 
 +++ 1.4.0
 
 Notes provide a place for you to store notes or general information on an object, such as a Device, that may not require a specific field for. This could be a note on a recent upgrade, a warning about a problematic device, or the reason the Rack was marked with the Status `Retired`.
 
-The note field supports [Markdown Basic Syntax](https://www.markdownguide.org/cheat-sheet/#basic-syntax).
+The note field supports [Markdown Basic Syntax](https://www.markdownguide.org/cheat-sheet/#basic-syntax) as well as [a limited subset of HTML](template-filters.md#render_markdown).
diff --git a/nautobot/docs/user-guide/platform-functionality/template-filters.md b/nautobot/docs/user-guide/platform-functionality/template-filters.md
index c210e4c46f..785378a3d9 100644
--- a/nautobot/docs/user-guide/platform-functionality/template-filters.md
+++ b/nautobot/docs/user-guide/platform-functionality/template-filters.md
@@ -214,16 +214,90 @@ Render a dictionary as formatted JSON.
 {{ data | render_json }}
 ```
 
 ### render_markdown
 
-Render text as Markdown.
+Render and sanitize Markdown text into HTML. A limited subset of HTML tags and attributes are permitted in the text as well; non-permitted HTML will be stripped from the output for security.
 
 ```django
 {{ text | render_markdown }}
 ```
 
+#### Permitted HTML Tags and Attributes
+
++++ 2.1.2
+
+The set of permitted HTML tags is defined in `nautobot.core.constants.HTML_ALLOWED_TAGS`, and their permitted attributes are defined in `nautobot.core.constants.HTML_ALLOWED_ATTRIBUTES`. As of Nautobot 2.1.2 the following are permitted:
+
+??? info "Full list of HTML tags and attributes"
+    | Tag            | Attributes                                                           |
+    | -------------- | -------------------------------------------------------------------- |
+    | `<a>`          | `href`, `hreflang`                                                   |
+    | `<abbr>`       |                                                                      |
+    | `<acronym>`    |                                                                      |
+    | `<b>`          |                                                                      |
+    | `<bdi>`        |                                                                      |
+    | `<bdo>`        | `dir`                                                                |
+    | `<blockquote>` | `cite`                                                               |
+    | `<br>`         |                                                                      |
+    | `<caption>`    |                                                                      |
+    | `<center>`     |                                                                      |
+    | `<cite>`       |                                                                      |
+    | `<code>`       |                                                                      |
+    | `<col>`        | `align`, `char`, `charoff`, `span`                                   |
+    | `<colgroup>`   | `align`, `char`, `charoff`, `span`                                   |
+    | `<dd>`         |                                                                      |
+    | `<del>`        | `cite`, `datetime`                                                   |
+    | `<details>`    |                                                                      |
+    | `<div>`        |                                                                      |
+    | `<dl>`         |                                                                      |
+    | `<dt>`         |                                                                      |
+    | `<em>`         |                                                                      |
+    | `<h1>`         |                                                                      |
+    | `<h2>`         |                                                                      |
+    | `<h3>`         |                                                                      |
+    | `<h4>`         |                                                                      |
+    | `<h5>`         |                                                                      |
+    | `<h6>`         |                                                                      |
+    | `<hgroup>`     |                                                                      |
+    | `<hr>`         | `align`, `size`, `width`                                             |
+    | `<i>`          |                                                                      |
+    | `<img>`        | `align`, `alt`, `height`, `src`, `width`                             |
+    | `<ins>`        | `cite`, `datetime`                                                   |
+    | `<kbd>`        |                                                                      |
+    | `<li>`         |                                                                      |
+    | `<mark>`       |                                                                      |
+    | `<ol>`         | `start`                                                              |
+    | `<p>`          |                                                                      |
+    | `<pre>`        |                                                                      |
+    | `<q>`          | `cite`                                                               |
+    | `<rp>`         |                                                                      |
+    | `<rt>`         |                                                                      |
+    | `<rtc>`        |                                                                      |
+    | `<ruby>`       |                                                                      |
+    | `
`          |                                                                      |
+    | `<samp>`       |                                                                      |
+    | `<small>`      |                                                                      |
+    | `<span>`       |                                                                      |
+    | `<strike>`     |                                                                      |
+    | `<strong>`     |                                                                      |
+    | `<sub>`        |                                                                      |
+    | `<summary>`    |                                                                      |
+    | `<sup>`        |                                                                      |
+    | `<table>`      | `align`, `char`, `charoff`, `summary`                                |
+    | `<tbody>`      | `align`, `char`, `charoff`                                           |
+    | `<td>`         | `align`, `char`, `charoff`, `colspan`, `headers`, `rowspan`          |
+    | `<th>`         | `align`, `char`, `charoff`, `colspan`, `headers`, `rowspan`, `scope` |
+    | `<thead>`      | `align`, `char`, `charoff`                                           |
+    | `<time>`       |                                                                      |
+    | `<tr>`         | `align`, `char`, `charoff`                                           |
+    | `<tt>`         |                                                                      |
+    | `<u>`          |                                                                      |
+    | `<ul>`         |                                                                      |
+    | `<var>`        |                                                                      |
+    | `<wbr>`        |                                                                      |
+
 ### render_yaml
 
 Render a dictionary as formatted YAML.
 
 ```django
diff --git a/nautobot/extras/forms/forms.py b/nautobot/extras/forms/forms.py
index 4c979f6e70..9b59fea959 100644
--- a/nautobot/extras/forms/forms.py
+++ b/nautobot/extras/forms/forms.py
@@ -366,23 +366,27 @@ CustomFieldChoiceFormSet = inlineformset_factory(
         "weight": forms.NumberInput(attrs={"class": "form-control"}),
     },
 )
 
 
+class CustomFieldDescriptionField(CommentField):
+    @property
+    def default_helptext(self):
+        return "Also used as the help text when editing models using this custom field.<br>" + super().default_helptext
+
+
 class CustomFieldForm(BootstrapMixin, forms.ModelForm):
     label = forms.CharField(required=True, max_length=50, help_text="Name of the field as displayed to users.")
     key = SlugField(
         label="Key",
         max_length=50,
         slug_source="label",
         help_text="Internal name of this field. Please use underscores rather than dashes.",
     )
-    description = forms.CharField(
+    description = CustomFieldDescriptionField(
+        label="Description",
         required=False,
-        help_text="Also used as the help text when editing models using this custom field.<br>"
-        '<a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet" target="_blank">'
-        "Markdown</a> syntax is supported.",
     )
     content_types = MultipleContentTypeField(
         feature="custom_fields", help_text="The object(s) to which this field applies."
     )
 
@@ -1096,11 +1100,11 @@ class JobButtonFilterForm(BootstrapMixin, forms.Form):
 # Notes
 #
 
 
 class NoteForm(BootstrapMixin, forms.ModelForm):
-    note = CommentField
+    note = CommentField()
 
     class Meta:
         model = Note
         fields = ["assigned_object_type", "assigned_object_id", "note"]
         widgets = {
diff --git a/nautobot/extras/models/jobs.py b/nautobot/extras/models/jobs.py
index a5894caa79..0b64802d3d 100644
--- a/nautobot/extras/models/jobs.py
+++ b/nautobot/extras/models/jobs.py
@@ -106,11 +106,14 @@ class Job(PrimaryModel):
     name = models.CharField(
         max_length=JOB_MAX_NAME_LENGTH,
         help_text="Human-readable name of this job",
         unique=True,
     )
-    description = models.TextField(blank=True, help_text="Markdown formatting is supported")
+    description = models.TextField(
+        blank=True,
+        help_text="Markdown formatting and a limited subset of HTML are supported",
+    )
 
     # Control flags
     installed = models.BooleanField(
         default=True,
         db_index=True,
diff --git a/poetry.lock b/poetry.lock
index 45cd9053a2..e4b8d370b3 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -1,6 +1,6 @@
-# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand.
+# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand.
 
 [[package]]
 name = "amqp"
 version = "5.2.0"
 description = "Low-level AMQP client for Python (fork of amqplib)."
@@ -1640,28 +1640,31 @@ name = "lxml"
 version = "5.1.0"
 description = "Powerful and Pythonic XML processing library combining libxml2/libxslt with the ElementTree API."
 optional = true
 python-versions = ">=3.6"
 files = [
+    {file = "lxml-5.1.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:704f5572ff473a5f897745abebc6df40f22d4133c1e0a1f124e4f2bd3330ff7e"},
     {file = "lxml-5.1.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:9d3c0f8567ffe7502d969c2c1b809892dc793b5d0665f602aad19895f8d508da"},
     {file = "lxml-5.1.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:5fcfbebdb0c5d8d18b84118842f31965d59ee3e66996ac842e21f957eb76138c"},
     {file = "lxml-5.1.0-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2f37c6d7106a9d6f0708d4e164b707037b7380fcd0b04c5bd9cae1fb46a856fb"},
     {file = "lxml-5.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2befa20a13f1a75c751f47e00929fb3433d67eb9923c2c0b364de449121f447c"},
     {file = "lxml-5.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:22b7ee4c35f374e2c20337a95502057964d7e35b996b1c667b5c65c567d2252a"},
     {file = "lxml-5.1.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:bf8443781533b8d37b295016a4b53c1494fa9a03573c09ca5104550c138d5c05"},
     {file = "lxml-5.1.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:82bddf0e72cb2af3cbba7cec1d2fd11fda0de6be8f4492223d4a268713ef2147"},
     {file = "lxml-5.1.0-cp310-cp310-win32.whl", hash = "sha256:b66aa6357b265670bb574f050ffceefb98549c721cf28351b748be1ef9577d93"},
     {file = "lxml-5.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:4946e7f59b7b6a9e27bef34422f645e9a368cb2be11bf1ef3cafc39a1f6ba68d"},
+    {file = "lxml-5.1.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:14deca1460b4b0f6b01f1ddc9557704e8b365f55c63070463f6c18619ebf964f"},
     {file = "lxml-5.1.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:ed8c3d2cd329bf779b7ed38db176738f3f8be637bb395ce9629fc76f78afe3d4"},
     {file = "lxml-5.1.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:436a943c2900bb98123b06437cdd30580a61340fbdb7b28aaf345a459c19046a"},
     {file = "lxml-5.1.0-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:acb6b2f96f60f70e7f34efe0c3ea34ca63f19ca63ce90019c6cbca6b676e81fa"},
     {file = "lxml-5.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:af8920ce4a55ff41167ddbc20077f5698c2e710ad3353d32a07d3264f3a2021e"},
     {file = "lxml-5.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7cfced4a069003d8913408e10ca8ed092c49a7f6cefee9bb74b6b3e860683b45"},
     {file = "lxml-5.1.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:9e5ac3437746189a9b4121db2a7b86056ac8786b12e88838696899328fc44bb2"},
     {file = "lxml-5.1.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:f4c9bda132ad108b387c33fabfea47866af87f4ea6ffb79418004f0521e63204"},
     {file = "lxml-5.1.0-cp311-cp311-win32.whl", hash = "sha256:bc64d1b1dab08f679fb89c368f4c05693f58a9faf744c4d390d7ed1d8223869b"},
     {file = "lxml-5.1.0-cp311-cp311-win_amd64.whl", hash = "sha256:a5ab722ae5a873d8dcee1f5f45ddd93c34210aed44ff2dc643b5025981908cda"},
+    {file = "lxml-5.1.0-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:9aa543980ab1fbf1720969af1d99095a548ea42e00361e727c58a40832439114"},
     {file = "lxml-5.1.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:6f11b77ec0979f7e4dc5ae081325a2946f1fe424148d3945f943ceaede98adb8"},
     {file = "lxml-5.1.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a36c506e5f8aeb40680491d39ed94670487ce6614b9d27cabe45d94cd5d63e1e"},
     {file = "lxml-5.1.0-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f643ffd2669ffd4b5a3e9b41c909b72b2a1d5e4915da90a77e119b8d48ce867a"},
     {file = "lxml-5.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:16dd953fb719f0ffc5bc067428fc9e88f599e15723a85618c45847c96f11f431"},
     {file = "lxml-5.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:16018f7099245157564d7148165132c70adb272fb5a17c048ba70d9cc542a1a1"},
@@ -1683,19 +1686,20 @@ files = [
     {file = "lxml-5.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:61c5a7edbd7c695e54fca029ceb351fc45cd8860119a0f83e48be44e1c464862"},
     {file = "lxml-5.1.0-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:3aeca824b38ca78d9ee2ab82bd9883083d0492d9d17df065ba3b94e88e4d7ee6"},
     {file = "lxml-5.1.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:8f52fe6859b9db71ee609b0c0a70fea5f1e71c3462ecf144ca800d3f434f0764"},
     {file = "lxml-5.1.0-cp37-cp37m-win32.whl", hash = "sha256:d42e3a3fc18acc88b838efded0e6ec3edf3e328a58c68fbd36a7263a874906c8"},
     {file = "lxml-5.1.0-cp37-cp37m-win_amd64.whl", hash = "sha256:eac68f96539b32fce2c9b47eb7c25bb2582bdaf1bbb360d25f564ee9e04c542b"},
+    {file = "lxml-5.1.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:ae15347a88cf8af0949a9872b57a320d2605ae069bcdf047677318bc0bba45b1"},
     {file = "lxml-5.1.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:c26aab6ea9c54d3bed716b8851c8bfc40cb249b8e9880e250d1eddde9f709bf5"},
-    {file = "lxml-5.1.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:cfbac9f6149174f76df7e08c2e28b19d74aed90cad60383ad8671d3af7d0502f"},
     {file = "lxml-5.1.0-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:342e95bddec3a698ac24378d61996b3ee5ba9acfeb253986002ac53c9a5f6f84"},
     {file = "lxml-5.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:725e171e0b99a66ec8605ac77fa12239dbe061482ac854d25720e2294652eeaa"},
     {file = "lxml-5.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3d184e0d5c918cff04cdde9dbdf9600e960161d773666958c9d7b565ccc60c45"},
     {file = "lxml-5.1.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:98f3f020a2b736566c707c8e034945c02aa94e124c24f77ca097c446f81b01f1"},
     {file = "lxml-5.1.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:6d48fc57e7c1e3df57be5ae8614bab6d4e7b60f65c5457915c26892c41afc59e"},
     {file = "lxml-5.1.0-cp38-cp38-win32.whl", hash = "sha256:7ec465e6549ed97e9f1e5ed51c657c9ede767bc1c11552f7f4d022c4df4a977a"},
     {file = "lxml-5.1.0-cp38-cp38-win_amd64.whl", hash = "sha256:b21b4031b53d25b0858d4e124f2f9131ffc1530431c6d1321805c90da78388d1"},
+    {file = "lxml-5.1.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:52427a7eadc98f9e62cb1368a5079ae826f94f05755d2d567d93ee1bc3ceb354"},
     {file = "lxml-5.1.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:6a2a2c724d97c1eb8cf966b16ca2915566a4904b9aad2ed9a09c748ffe14f969"},
     {file = "lxml-5.1.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:843b9c835580d52828d8f69ea4302537337a21e6b4f1ec711a52241ba4a824f3"},
     {file = "lxml-5.1.0-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9b99f564659cfa704a2dd82d0684207b1aadf7d02d33e54845f9fc78e06b7581"},
     {file = "lxml-5.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4f8b0c78e7aac24979ef09b7f50da871c2de2def043d468c4b41f512d831e912"},
     {file = "lxml-5.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9bcf86dfc8ff3e992fed847c077bd875d9e0ba2fa25d859c3a0f0f76f07f0c8d"},
@@ -2169,10 +2173,35 @@ files = [
 ]
 
 [package.extras]
 optionals = ["jsonschema (>=4.17.3,<5.0.0)", "napalm (>=4.0.0,<5.0.0)"]
 
+[[package]]
+name = "nh3"
+version = "0.2.15"
+description = "Python bindings to the ammonia HTML sanitization library."
+optional = false
+python-versions = "*"
+files = [
+    {file = "nh3-0.2.15-cp37-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:9c0d415f6b7f2338f93035bba5c0d8c1b464e538bfbb1d598acd47d7969284f0"},
+    {file = "nh3-0.2.15-cp37-abi3-macosx_10_12_x86_64.whl", hash = "sha256:6f42f99f0cf6312e470b6c09e04da31f9abaadcd3eb591d7d1a88ea931dca7f3"},
+    {file = "nh3-0.2.15-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ac19c0d68cd42ecd7ead91a3a032fdfff23d29302dbb1311e641a130dfefba97"},
+    {file = "nh3-0.2.15-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:5f0d77272ce6d34db6c87b4f894f037d55183d9518f948bba236fe81e2bb4e28"},
+    {file = "nh3-0.2.15-cp37-abi3-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:8d595df02413aa38586c24811237e95937ef18304e108b7e92c890a06793e3bf"},
+    {file = "nh3-0.2.15-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:86e447a63ca0b16318deb62498db4f76fc60699ce0a1231262880b38b6cff911"},
+    {file = "nh3-0.2.15-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3277481293b868b2715907310c7be0f1b9d10491d5adf9fce11756a97e97eddf"},
+    {file = "nh3-0.2.15-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:60684857cfa8fdbb74daa867e5cad3f0c9789415aba660614fe16cd66cbb9ec7"},
+    {file = "nh3-0.2.15-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:3b803a5875e7234907f7d64777dfde2b93db992376f3d6d7af7f3bc347deb305"},
+    {file = "nh3-0.2.15-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:0d02d0ff79dfd8208ed25a39c12cbda092388fff7f1662466e27d97ad011b770"},
+    {file = "nh3-0.2.15-cp37-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:f3b53ba93bb7725acab1e030bc2ecd012a817040fd7851b332f86e2f9bb98dc6"},
+    {file = "nh3-0.2.15-cp37-abi3-musllinux_1_2_i686.whl", hash = "sha256:b1e97221cedaf15a54f5243f2c5894bb12ca951ae4ddfd02a9d4ea9df9e1a29d"},
+    {file = "nh3-0.2.15-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:a5167a6403d19c515217b6bcaaa9be420974a6ac30e0da9e84d4fc67a5d474c5"},
+    {file = "nh3-0.2.15-cp37-abi3-win32.whl", hash = "sha256:427fecbb1031db085eaac9931362adf4a796428ef0163070c484b5a768e71601"},
+    {file = "nh3-0.2.15-cp37-abi3-win_amd64.whl", hash = "sha256:bc2d086fb540d0fa52ce35afaded4ea526b8fc4d3339f783db55c95de40ef02e"},
+    {file = "nh3-0.2.15.tar.gz", hash = "sha256:d1e30ff2d8d58fb2a14961f7aac1bbb1c51f9bdd7da727be35c63826060b0bf3"},
+]
+
 [[package]]
 name = "ntc-templates"
 version = "4.1.0"
 description = "TextFSM Templates for Network Devices, and Python wrapper for TextFSM's CliTable."
 optional = true
@@ -2426,21 +2455,18 @@ files = [
     {file = "psycopg2_binary-2.9.9-cp311-cp311-musllinux_1_1_ppc64le.whl", hash = "sha256:77853062a2c45be16fd6b8d6de2a99278ee1d985a7bd8b103e97e41c034006d2"},
     {file = "psycopg2_binary-2.9.9-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:78151aa3ec21dccd5cdef6c74c3e73386dcdfaf19bced944169697d7ac7482fc"},
     {file = "psycopg2_binary-2.9.9-cp311-cp311-win32.whl", hash = "sha256:dc4926288b2a3e9fd7b50dc6a1909a13bbdadfc67d93f3374d984e56f885579d"},
     {file = "psycopg2_binary-2.9.9-cp311-cp311-win_amd64.whl", hash = "sha256:b76bedd166805480ab069612119ea636f5ab8f8771e640ae103e05a4aae3e417"},
     {file = "psycopg2_binary-2.9.9-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:8532fd6e6e2dc57bcb3bc90b079c60de896d2128c5d9d6f24a63875a95a088cf"},
-    {file = "psycopg2_binary-2.9.9-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:b0605eaed3eb239e87df0d5e3c6489daae3f7388d455d0c0b4df899519c6a38d"},
     {file = "psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8f8544b092a29a6ddd72f3556a9fcf249ec412e10ad28be6a0c0d948924f2212"},
     {file = "psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2d423c8d8a3c82d08fe8af900ad5b613ce3632a1249fd6a223941d0735fce493"},
     {file = "psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:2e5afae772c00980525f6d6ecf7cbca55676296b580c0e6abb407f15f3706996"},
     {file = "psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6e6f98446430fdf41bd36d4faa6cb409f5140c1c2cf58ce0bbdaf16af7d3f119"},
     {file = "psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:c77e3d1862452565875eb31bdb45ac62502feabbd53429fdc39a1cc341d681ba"},
     {file = "psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:cb16c65dcb648d0a43a2521f2f0a2300f40639f6f8c1ecbc662141e4e3e1ee07"},
     {file = "psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_ppc64le.whl", hash = "sha256:911dda9c487075abd54e644ccdf5e5c16773470a6a5d3826fda76699410066fb"},
     {file = "psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:57fede879f08d23c85140a360c6a77709113efd1c993923c59fde17aa27599fe"},
-    {file = "psycopg2_binary-2.9.9-cp312-cp312-win32.whl", hash = "sha256:64cf30263844fa208851ebb13b0732ce674d8ec6a0c86a4e160495d299ba3c93"},
-    {file = "psycopg2_binary-2.9.9-cp312-cp312-win_amd64.whl", hash = "sha256:81ff62668af011f9a48787564ab7eded4e9fb17a4a6a74af5ffa6a457400d2ab"},
     {file = "psycopg2_binary-2.9.9-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:2293b001e319ab0d869d660a704942c9e2cce19745262a8aba2115ef41a0a42a"},
     {file = "psycopg2_binary-2.9.9-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:03ef7df18daf2c4c07e2695e8cfd5ee7f748a1d54d802330985a78d2a5a6dca9"},
     {file = "psycopg2_binary-2.9.9-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0a602ea5aff39bb9fac6308e9c9d82b9a35c2bf288e184a816002c9fae930b77"},
     {file = "psycopg2_binary-2.9.9-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8359bf4791968c5a78c56103702000105501adb557f3cf772b2c207284273984"},
     {file = "psycopg2_binary-2.9.9-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:275ff571376626195ab95a746e6a04c7df8ea34638b99fc11160de91f2fef503"},
@@ -3955,6 +3981,6 @@ remote-storage = ["django-storages"]
 sso = ["social-auth-core"]
 
 [metadata]
 lock-version = "2.0"
 python-versions = ">=3.8,<3.12"
-content-hash = "8138e21579db269494e43aa441e2690b0bf838b58c6cce161dcb9f4cd1852640"
+content-hash = "136fa4c518d4206074a6f43319274580a9fd1c9ccc7e32b8045e767a0f8bcd12"
diff --git a/pyproject.toml b/pyproject.toml
index 2b6e171a70..15e9402524 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -110,10 +110,12 @@ napalm = {version = "~4.1.0", optional = true}
 netaddr = "~0.8.0"
 # Library of network related utilities including network driver mappings and Jinja Filters
 # Note: netutils is limited in scope, dependencies, and observes semver, as such
 #       we permit a looser (^) version constraint here.
 netutils = "^1.6.0"
+# HTML sanitization
+nh3 = "~0.2.15"
 # Handling of version numbers
 packaging = ">=23.1"
 # Image processing library
 Pillow = "~10.0.0"
 # Custom prometheus metrics

Vulnerable code:     # TODO: Port Markdown cheat sheet to internal documentation
    default_helptext = (
        '<i class="mdi mdi-information-outline"></i> '
        '<a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet" target="_blank">'
        "Markdown</a> syntax is supported"
    )
        help_text="Help message to include on 4xx and 5xx error pages. Markdown is supported.\n"
from django.utils.html import format_html, strip_tags
from nautobot.core.utils import color, config, data, lookup
    # Strip HTML tags
    value = strip_tags(value)

    # Sanitize Markdown links
    schemes = "|".join(settings.ALLOWED_URL_SCHEMES)
    pattern = rf"\[(.+)\]\((?!({schemes})).*:(.+)\)"
    value = re.sub(pattern, "[\\1](\\3)", value, flags=re.IGNORECASE)

        self.assertEqual(
            '<p><a href="https://www.example.com">I am a link</a></p>',
                    'on <a href="https://slack.networktocode.com/">Network to Code\'s Slack community</a> '
                    "and post your question.</p>",
            "If further assistance is required, please join the <code>#nautobot</code> channel "
            'on <a href="https://slack.networktocode.com/">Network to Code\'s Slack community</a> '
            "and post your question.",
            "If further assistance is required, please join the <code>#nautobot</code> channel "
            'on <a href="https://slack.networktocode.com/">Network to Code\'s Slack community</a> '
            "and post your question.",
        """Nautobot's custom 500 page should be used and should include a default support message."""
"""Utilities for working with log messages and similar features."""
This can accept either plain text or Markdown-formatted text. It can also be multiple lines:
Markdown rendering is supported for log messages.
A message to include on error pages (status code 403, 404, 500, etc.) when an error occurs. You can configure this to direct users to the appropriate contact(s) within your organization that provide support for Nautobot. Markdown formatting is supported within this message (raw HTML is not).
The note field supports [Markdown Basic Syntax](https://www.markdownguide.org/cheat-sheet/#basic-syntax).
Render text as Markdown.
    description = forms.CharField(
        help_text="Also used as the help text when editing models using this custom field.<br>"
        '<a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet" target="_blank">'
        "Markdown</a> syntax is supported.",
    note = CommentField
    description = models.TextField(blank=True, help_text="Markdown formatting is supported")
# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand.
    {file = "lxml-5.1.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:cfbac9f6149174f76df7e08c2e28b19d74aed90cad60383ad8671d3af7d0502f"},
    {file = "psycopg2_binary-2.9.9-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:b0605eaed3eb239e87df0d5e3c6489daae3f7388d455d0c0b4df899519c6a38d"},
    {file = "psycopg2_binary-2.9.9-cp312-cp312-win32.whl", hash = "sha256:64cf30263844fa208851ebb13b0732ce674d8ec6a0c86a4e160495d299ba3c93"},
    {file = "psycopg2_binary-2.9.9-cp312-cp312-win_amd64.whl", hash = "sha256:81ff62668af011f9a48787564ab7eded4e9fb17a4a6a74af5ffa6a457400d2ab"},
content-hash = "8138e21579db269494e43aa441e2690b0bf838b58c6cce161dcb9f4cd1852640"
Fixed code: Enhanced Markdown-supporting fields (`comments`, `description`, Notes, Job log entries, etc.) to also permit the use of a limited subset of "safe" HTML tags and attributes.
Added `nh3` HTML sanitization library as a dependency.
Fixed an XSS vulnerability ([GHSA-v4xv-795h-rv4h](https://github.com/nautobot/nautobot/security/advisories/GHSA-v4xv-795h-rv4h)) in the `render_markdown()` utility function used to render comments, notes, job log entries, etc.
from copy import deepcopy

import nh3

#
# User input sanitization
#

# Subset of the HTML tags allowed by default by ammonia:
# https://github.com/rust-ammonia/ammonia/blob/master/src/lib.rs
HTML_ALLOWED_TAGS = nh3.ALLOWED_TAGS - {
    # no image maps at present
    "area",
    "map",
    # no document-level markup at present
    "article",
    "aside",
    "footer",
    "header",
    "nav",
    # miscellaneous out-of-scope for now
    "data",
    "dfn",
    "figcaption",
    "figure",
}

# Variant of the HTML attributes allowed by default by ammonia:
# https://github.com/rust-ammonia/ammonia/blob/master/src/lib.rs
# at present we just copy nh3.ALLOWED_ATTRIBUTES but we can modify this later as desired and appropriate
HTML_ALLOWED_ATTRIBUTES = deepcopy(nh3.ALLOWED_ATTRIBUTES)


from django.templatetags.static import static
from django.utils.html import format_html

    @property
    def default_helptext(self):
        # TODO: Port Markdown cheat sheet to internal documentation
        return format_html(
            '<i class="mdi mdi-information-outline"></i> '
            '<a href="https://www.markdownguide.org/cheat-sheet/#basic-syntax" rel="noopener noreferrer">Markdown</a> '
            'syntax is supported, as well as <a href="{}#render_markdown">a limited subset of HTML</a>.',
            static("docs/user-guide/platform-functionality/template-filters.html"),
        )
        help_text="Help message to include on 4xx and 5xx error pages. "
        "Markdown is supported, as are some HTML tags and attributes.\n"
from django.utils.html import format_html
from nautobot.core.utils import color, config, data, logging as nautobot_logging, lookup
    # Sanitize rendered HTML
    html = nautobot_logging.clean_html(html)

        self.assertHTMLEqual(
            '<p><a href="https://www.example.com" rel="noopener noreferrer">I am a link</a></p>',
        )

    def test_render_markdown_security(self):
        self.assertEqual(helpers.render_markdown('<script>alert("XSS")</script>'), "")
        self.assertHTMLEqual(
            helpers.render_markdown('[link](javascript:alert("XSS"))'),
            '<p><a title="XSS" rel="noopener noreferrer">link</a>)</p>',  # the trailing ) seems weird to me, but...
        )
        self.assertHTMLEqual(
            helpers.render_markdown(
                "[link\nJS]"
                "(&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A"  # '(javascript:'
                "&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29)"  # 'alert("XSS"))'
            ),
            '<p><a rel="noopener noreferrer">link JS</a></p>',
                    'on <a href="https://slack.networktocode.com/" rel="noopener noreferrer">Network to Code\'s '
                    "Slack community</a> and post your question.</p>",
            "If further assistance is required, please join the <code>#nautobot</code> channel on "
            '<a href="https://slack.networktocode.com/" rel="noopener noreferrer">Network to Code\'s '
            "Slack community</a> and post your question.",
            "If further assistance is required, please join the <code>#nautobot</code> channel on "
            '<a href="https://slack.networktocode.com/" rel="noopener noreferrer">Network to Code\'s '
            "Slack community</a> and post your question.",
        """Nautobot's custom 500 page should be used and should include a custom support message if defined."""
"""Utilities for working with log messages and similar user-authored data."""
import nh3

from nautobot.core import constants


def clean_html(html):
    """Use nh3/ammonia to strip out all HTML tags and attributes except those explicitly permitted."""
    return nh3.clean(
        html,
        tags=constants.HTML_ALLOWED_TAGS,
        attributes=constants.HTML_ALLOWED_ATTRIBUTES,
        url_schemes=set(settings.ALLOWED_URL_SCHEMES),
    )
This can accept either plain text, Markdown-formatted text, or [a limited subset of HTML](../../user-guide/platform-functionality/template-filters.md#render_markdown). It can also be multiple lines:
Markdown rendering is supported for log messages, as well as [a limited subset of HTML](../../user-guide/platform-functionality/template-filters.md#render_markdown).
A message to include on error pages (status code 403, 404, 500, etc.) when an error occurs. You can configure this to direct users to the appropriate contact(s) within your organization that provide support for Nautobot. Markdown formatting is supported within this message, as well as [a limited subset of HTML](../../platform-functionality/template-filters.md#render_markdown).
The note field supports [Markdown Basic Syntax](https://www.markdownguide.org/cheat-sheet/#basic-syntax) as well as [a limited subset of HTML](template-filters.md#render_markdown).
Render and sanitize Markdown text into HTML. A limited subset of HTML tags and attributes are permitted in the text as well; non-permitted HTML will be stripped from the output for security.
#### Permitted HTML Tags and Attributes


The set of permitted HTML tags is defined in `nautobot.core.constants.HTML_ALLOWED_TAGS`, and their permitted attributes are defined in `nautobot.core.constants.HTML_ALLOWED_ATTRIBUTES`. As of Nautobot 2.1.2 the following are permitted:

??? info "Full list of HTML tags and attributes"
    | Tag            | Attributes                                                           |
    | -------------- | -------------------------------------------------------------------- |
    | `<a>`          | `href`, `hreflang`                                                   |
    | `<abbr>`       |                                                                      |
    | `<acronym>`    |                                                                      |
    | `<b>`          |                                                                      |
    | `<bdi>`        |                                                                      |
    | `<bdo>`        | `dir`                                                                |
    | `<blockquote>` | `cite`                                                               |
    | `<br>`         |                                                                      |
    | `<caption>`    |                                                                      |
    | `<center>`     |                                                                      |
    | `<cite>`       |                                                                      |
    | `<code>`       |                                                                      |
    | `<col>`        | `align`, `char`, `charoff`, `span`                                   |
    | `<colgroup>`   | `align`, `char`, `charoff`, `span`                                   |
    | `<dd>`         |                                                                      |
    | `<del>`        | `cite`, `datetime`                                                   |
    | `<details>`    |                                                                      |
    | `<div>`        |                                                                      |
    | `<dl>`         |                                                                      |
    | `<dt>`         |                                                                      |
    | `<em>`         |                                                                      |
    | `<h1>`         |                                                                      |
    | `<h2>`         |                                                                      |
    | `<h3>`         |                                                                      |
    | `<h4>`         |                                                                      |
    | `<h5>`         |                                                                      |
    | `<h6>`         |                                                                      |
    | `<hgroup>`     |                                                                      |
    | `<hr>`         | `align`, `size`, `width`                                             |
    | `<i>`          |                                                                      |
    | `<img>`        | `align`, `alt`, `height`, `src`, `width`                             |
    | `<ins>`        | `cite`, `datetime`                                                   |
    | `<kbd>`        |                                                                      |
    | `<li>`         |                                                                      |
    | `<mark>`       |                                                                      |
    | `<ol>`         | `start`                                                              |
    | `<p>`          |                                                                      |
    | `<pre>`        |                                                                      |
    | `<q>`          | `cite`                                                               |
    | `<rp>`         |                                                                      |
    | `<rt>`         |                                                                      |
    | `<rtc>`        |                                                                      |
    | `<ruby>`       |                                                                      |
    | `
`          |                                                                      |
    | `<samp>`       |                                                                      |
    | `<small>`      |                                                                      |
    | `<span>`       |                                                                      |
    | `<strike>`     |                                                                      |
    | `<strong>`     |                                                                      |
    | `<sub>`        |                                                                      |
    | `<summary>`    |                                                                      |
    | `<sup>`        |                                                                      |
    | `<table>`      | `align`, `char`, `charoff`, `summary`                                |
    | `<tbody>`      | `align`, `char`, `charoff`                                           |
    | `<td>`         | `align`, `char`, `charoff`, `colspan`, `headers`, `rowspan`          |
    | `<th>`         | `align`, `char`, `charoff`, `colspan`, `headers`, `rowspan`, `scope` |
    | `<thead>`      | `align`, `char`, `charoff`                                           |
    | `<time>`       |                                                                      |
    | `<tr>`         | `align`, `char`, `charoff`                                           |
    | `<tt>`         |                                                                      |
    | `<u>`          |                                                                      |
    | `<ul>`         |                                                                      |
    | `<var>`        |                                                                      |
    | `<wbr>`        |                                                                      |

class CustomFieldDescriptionField(CommentField):
    @property
    def default_helptext(self):
        return "Also used as the help text when editing models using this custom field.<br>" + super().default_helptext


    description = CustomFieldDescriptionField(
        label="Description",
    note = CommentField()
    description = models.TextField(
        blank=True,
        help_text="Markdown formatting and a limited subset of HTML are supported",
    )
# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand.
    {file = "lxml-5.1.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:704f5572ff473a5f897745abebc6df40f22d4133c1e0a1f124e4f2bd3330ff7e"},
    {file = "lxml-5.1.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:14deca1460b4b0f6b01f1ddc9557704e8b365f55c63070463f6c18619ebf964f"},
    {file = "lxml-5.1.0-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:9aa543980ab1fbf1720969af1d99095a548ea42e00361e727c58a40832439114"},
    {file = "lxml-5.1.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:ae15347a88cf8af0949a9872b57a320d2605ae069bcdf047677318bc0bba45b1"},
    {file = "lxml-5.1.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:52427a7eadc98f9e62cb1368a5079ae826f94f05755d2d567d93ee1bc3ceb354"},
[[package]]
name = "nh3"
version = "0.2.15"
description = "Python bindings to the ammonia HTML sanitization library."
optional = false
python-versions = "*"
files = [
    {file = "nh3-0.2.15-cp37-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:9c0d415f6b7f2338f93035bba5c0d8c1b464e538bfbb1d598acd47d7969284f0"},
    {file = "nh3-0.2.15-cp37-abi3-macosx_10_12_x86_64.whl", hash = "sha256:6f42f99f0cf6312e470b6c09e04da31f9abaadcd3eb591d7d1a88ea931dca7f3"},
    {file = "nh3-0.2.15-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ac19c0d68cd42ecd7ead91a3a032fdfff23d29302dbb1311e641a130dfefba97"},
    {file = "nh3-0.2.15-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:5f0d77272ce6d34db6c87b4f894f037d55183d9518f948bba236fe81e2bb4e28"},
    {file = "nh3-0.2.15-cp37-abi3-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:8d595df02413aa38586c24811237e95937ef18304e108b7e92c890a06793e3bf"},
    {file = "nh3-0.2.15-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:86e447a63ca0b16318deb62498db4f76fc60699ce0a1231262880b38b6cff911"},
    {file = "nh3-0.2.15-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3277481293b868b2715907310c7be0f1b9d10491d5adf9fce11756a97e97eddf"},
    {file = "nh3-0.2.15-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:60684857cfa8fdbb74daa867e5cad3f0c9789415aba660614fe16cd66cbb9ec7"},
    {file = "nh3-0.2.15-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:3b803a5875e7234907f7d64777dfde2b93db992376f3d6d7af7f3bc347deb305"},
    {file = "nh3-0.2.15-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:0d02d0ff79dfd8208ed25a39c12cbda092388fff7f1662466e27d97ad011b770"},
    {file = "nh3-0.2.15-cp37-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:f3b53ba93bb7725acab1e030bc2ecd012a817040fd7851b332f86e2f9bb98dc6"},
    {file = "nh3-0.2.15-cp37-abi3-musllinux_1_2_i686.whl", hash = "sha256:b1e97221cedaf15a54f5243f2c5894bb12ca951ae4ddfd02a9d4ea9df9e1a29d"},
    {file = "nh3-0.2.15-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:a5167a6403d19c515217b6bcaaa9be420974a6ac30e0da9e84d4fc67a5d474c5"},
    {file = "nh3-0.2.15-cp37-abi3-win32.whl", hash = "sha256:427fecbb1031db085eaac9931362adf4a796428ef0163070c484b5a768e71601"},
    {file = "nh3-0.2.15-cp37-abi3-win_amd64.whl", hash = "sha256:bc2d086fb540d0fa52ce35afaded4ea526b8fc4d3339f783db55c95de40ef02e"},
    {file = "nh3-0.2.15.tar.gz", hash = "sha256:d1e30ff2d8d58fb2a14961f7aac1bbb1c51f9bdd7da727be35c63826060b0bf3"},
]

content-hash = "136fa4c518d4206074a6f43319274580a9fd1c9ccc7e32b8045e767a0f8bcd12"
# HTML sanitization
nh3 = "~0.2.15"